How to plot a cell array containing characters?
古いコメントを表示
Hi everyone.
I have a cell array (1x1000) that looks like this:
comment=[artefact artefact 0 0 0 0 ...] ;
How can I plot the strings of this array against other values already plotted as lines?
3 件のコメント
Jan
2022 年 4 月 15 日
comment=[artefact artefact 0 0 0 0 ...] ;
This is not a cell array. Please post some code, which really procudes the variables you are talking of.
I have no idea, how you want to "plot" a string or CHAR vector.
Mariagrazia Ambrosino
2022 年 4 月 15 日
編集済み: Mariagrazia Ambrosino
2022 年 4 月 15 日
Image Analyst
2022 年 4 月 19 日
Again, attach your cell array with the paperclip icon
save('Answers.mat', 'comment');
after you read this link:
回答 (1 件)
% you have a 1x1000 cell array called 'comment':
comment = repmat({0},1,1000);
comment([1 2]) = {"artefact"};
disp(comment);
% and you have already plotted the lines:
figure
xlim([0 5]*1e6);
ylim([-4000 4000]);
hold on
plot([0 0 NaN 1.3 1.3 NaN 4.52 4.52 NaN]*1e6,[-4000 4000 NaN -4000 4000 NaN -4000 4000 NaN],'--r');
% here's how you can make the texts:
text(0,0,comment{1});
text(1.3e6,0,comment{2},'Rotation',90)
text(4.52e6,0,comment{2},'Rotation',-45);
4 件のコメント
Mariagrazia Ambrosino
2022 年 4 月 19 日
You can use isstring or ischar to determine whether something is a string or a character array, respectively.
% some comments:
words = split('now is the winter of our discontent');
% put them into a cell array at random indices:
idx = cumsum(randi(5,1,numel(words)));
comment = repmat({0},1,idx(end));
comment(idx) = words
% make text objects showing the comments (use ischar to determine whether
% a particular cell of cell array 'comment' contains a comment)
for ii = 1:numel(comment)
if ischar(comment{ii})
text(ii,ii,comment{ii});
end
end
grid on
xlim([0 ii+1]);
ylim([0 ii+1]);
Mariagrazia Ambrosino
2022 年 4 月 20 日
Voss
2022 年 4 月 20 日
You're welcome! If you have any other questions, let me know. Otherwise, if my answer satisfactorily addresses what you're trying to do, please click 'Accept this Answer'. Thanks!
カテゴリ
ヘルプ センター および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


