Effacer les filtres
Effacer les filtres

Why can't I use a 1x19 string to assign y-tick values on a barh plot?

3 vues (au cours des 30 derniers jours)
The labels for my bar plot are assigned based on a previous for loop, which could vary in length depending on the data I am processing. This produces a 1xn string. I am trying to use that string to assign the y-tick labels for the chart, but only the first value is being plotted.
Any help with this?
%%Producing the bar labels
for i5=1:Doff
DoffValue(:,i5)=DoffOutput(:,3,i5);
DoffColour(:,i5)=DoffOutput(:,2,i5);
DoffTime(1,i5)=(DoffOutput(Time,1,i5)-(fix(c(1,1))));
Day(1,i5)=fix(DoffTime(1,i5));
Hour(1,i5)=fix((DoffTime(1,i5)-fix(DoffTime(1,i5)))*24);
MinuteCount(1,i5)=fix((((DoffTime(1,i5)-fix(DoffTime(1,i5)))*24)-Hour(1,i5))*60);
DoffTimeText(i5)=sprintf("Day %d %d:%d",Day(1,i5),Hour(1,i5),MinuteCount(1,i5));
end
%% Assigning y-tick labels
yticklabels(DoffTimeText);

Réponse acceptée

chicken vector
chicken vector le 28 Avr 2023
Modifié(e) : chicken vector le 28 Avr 2023
You also have to setup the location of the ticks accordingly.
In the following example I set the range of y axis between 0 and 1 and if I want to display 5 ticks labels I have to specify their location using 'YTick'.
Is similar to use Coordinate-Value pairs.
data = rand(50,2);
tickText = cell(5,1);
for j = 1 : length(tickText)
tickText{j} = ['This is Tick ' num2str(j)];
end
yRange = [0,1];
ticks = yRange(1):diff(yRange)/(length(tickText)-1):yRange(2);
figure;
grid on;
scatter(data(:,1),data(:,2),50,'d','filled')
set(gca,'YTick',ticks,'YTickLabel',tickText)
tickText
tickText = 5×1 cell array
{'This is Tick 1'} {'This is Tick 2'} {'This is Tick 3'} {'This is Tick 4'} {'This is Tick 5'}
ticks
ticks = 1×5
0 0.2500 0.5000 0.7500 1.0000
You can invert the order with flip.
figure;
grid on;
scatter(data(:,1),data(:,2),50,'d','filled')
set(gca,'YTick',ticks,'YTickLabel',flip(tickText))
  2 commentaires
Nicolaas Pickard
Nicolaas Pickard le 28 Avr 2023
Thanks very much for your help :) managed to get it sorted.
chicken vector
chicken vector le 28 Avr 2023
Happy to hear that

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by