フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How can I have the title on a graph change depending on whats in the graph?

1 回表示 (過去 30 日間)
Nicholas Connolly
Nicholas Connolly 2020 年 11 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have created 7 graphs, all of them are comparing different things, but the y axis is the same in all. I have a working for loop generating the graphs. I was wondering if I can add the title into the loop so it creates the title based on what is in the x axis of the plot. The code below plots them perfectly, I am just looking for a way to add a unique title to each.
for i = 1:numel(xcardata)
figure(i)
plot(xcardata{i}, ycardata, 'ob')
end

回答 (1 件)

Star Strider
Star Strider 2020 年 11 月 7 日
Use sprintf in the title.
Example —
x = 1:0.1:5;
for k = 1:5
y = x.^k;
figure
plot(x, y)
title(sprintf('y = x^{%d}',k))
end
.
  2 件のコメント
Nicholas Connolly
Nicholas Connolly 2020 年 11 月 8 日
I understand the concept, but I am trying to add words, does the %d only work for numbers? I cant seem to get it to work. For example say I have a list of words such as (apple, dog, bannana, icecream) how do I make each of those titles on a seperate graph.
Star Strider
Star Strider 2020 年 11 月 8 日
Choose the text you want in the title sprintf call, then use '%s' instead to write character vectors , i.e. words.
See the sprintf documentation section on formatSpec for details.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by