フィルターのクリア

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

3 ビュー (過去 30 日間)
Nicolaas Pickard
Nicolaas Pickard 2023 年 4 月 28 日
コメント済み: chicken vector 2023 年 4 月 28 日
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))
  2 件のコメント
Nicolaas Pickard
Nicolaas Pickard 2023 年 4 月 28 日
Thanks very much for your help :) managed to get it sorted.
chicken vector
chicken vector 2023 年 4 月 28 日
Happy to hear that

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by