필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
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);

채택된 답변

chicken vector
chicken vector 2023년 4월 28일
편집: chicken vector 2023년 4월 28일
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))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by