필터 지우기
필터 지우기

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