How to include labels to a plot?
1 回表示 (過去 30 日間)
古いコメントを表示
So I have some coordinates and I want to include some labels on my plot.
force = 30;
displacement = [10 20 30 40];
cases = ['This is case 1' 'This is case 2' 'This is case 3' 'This is case 4'];
plot (force, displacement, 'x')
for i =1:length(displacement)
text(force, displacement(i), ['\leftarrow ', cases(i)]);
end
I know the problem is with either line 3 or line 6 because cases is saved as char and when I call cases(i) in line 6 it displays only the individual characters instead of everything that is inside the quotation(' ') marks. Does anyone know how to fix this?
0 件のコメント
採用された回答
Kevin Holly
2022 年 11 月 6 日
編集済み: Kevin Holly
2022 年 11 月 6 日
force = 30;
displacement = [10 20 30 40];
cases = ["This is case 1" "This is case 2" "This is case 3" "This is case 4"];
plot (force, displacement, 'x')
for i =1:length(displacement)
text(force, displacement(i), ['\leftarrow ', char(cases(i))]);
end
2 件のコメント
Kevin Holly
2022 年 11 月 6 日
Using double quotes creates a string array, where characters enclosed are treated as a single elements.
string_array = "This is case 1";
size(string_array)
Character arrays use single quotes. In this case, each character is treated as a separate element.
character_array = 'This is case 1';
size(character_array)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!