convert or translat number to specific word using it for title

1 回表示 (過去 30 日間)
Yousif Alaraji
Yousif Alaraji 2023 年 3 月 26 日
編集済み: Adam Danz 2023 年 3 月 26 日
I am trying to generate a title for my Plot that work according to a Number so lets say if the Number is (1) then the word will be (Normal) if the Number is (2) the words will be (Level1) ..etc
I used the below code for the Title using (renamecats) function but It didn't work I don't know why.
for n = 1:numel(out(1,:))
x=out(2:end,n);
subplot(4,2,n);
plot(t,x);
if n == 3 || n == 4
xlabel('Seconds');
end
title(renamecats({n},string(catnames)));
end
Best Regards,
Yousif
  1 件のコメント
Adam Danz
Adam Danz 2023 年 3 月 26 日
編集済み: Adam Danz 2023 年 3 月 26 日
I think you just need to replace the title(__) line with
title(catnames(n));
or, is the problem that the categorical values are not in the intended order?

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

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 3 月 26 日
Here is onee of the possible solutions with one simple example:
T = randn(4, 15);
t=1:15;
catnames = {'Normal', 'Level 1', 'Level 2', 'Level 3'};
for n = 1:size(T,1)
switch n
case 1
x=T(n,:);
subplot(4,2,n);
plot(t,x);
title (catnames{n})
case 2
x=T(n,:);
subplot(4,2,n);
plot(t,x);
title (catnames{n})
case 3
x=T(n,:);
subplot(4,2,n);
plot(t,x);
title (catnames{n})
case 4
x=T(n,:);
subplot(4,2,n);
plot(t,x);
title (catnames{n})
end
end
  2 件のコメント
Yousif Alaraji
Yousif Alaraji 2023 年 3 月 26 日
Many thanks dear,
I also used
d=dictionary([1,2,3,4],catnames);
title(d(n));
also works,
Yousif Alaraji
Yousif Alaraji 2023 年 3 月 26 日
Yes dear thank you

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by