フィルターのクリア

Add element to legend outside for loop

14 ビュー (過去 30 日間)
Yvet
Yvet 2021 年 2 月 23 日
回答済み: Jemima Pulipati 2021 年 2 月 25 日
Hi all,
I have a for loop creating 1 figure with multiple lines in it.
Outside of the for loop, I'm adding 1 more line (which can't be done within the for loop).
My legend has a value for each iteration in the for loop, but now I want to add the value of the line outside the for loop as well.
How can I do this?
test = [1 2 3 4 5 6 7 8];
test2 = [11 12 13 14 15];
for i=1:length(test)
for j=1:length(test2)
results(j,:) = [value1 value2 value3];
end
plot(results(:,1),results(:,2))
xlabel('value1')
ylabel('value2')
legend(strcat('This is my test: a = ',num2str(test')))
end
plot(results(:,1),results(:,3)) % I only need these values for the very last iteration
legend('some text no numbers or values')
  3 件のコメント
Yvet
Yvet 2021 年 2 月 23 日
Thank you for your quick reply!
It now partly works. It indeed adds the 'some text no numbers or values' to the legend, But it doesn't show the color line in the legend for all iterations. Do you know how I can solve this?
Yvet
Yvet 2021 年 2 月 23 日
And do you perhaps also know how I could find the intersection between each 'test' line and the 'test2' line? The numbers in the arrays used for plotting will not be exactly the same at the intersection point, so I can't use intersect.

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

回答 (1 件)

Jemima Pulipati
Jemima Pulipati 2021 年 2 月 25 日

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by