フィルターのクリア

How to create one plot with multiple lines in a for loop?

58 ビュー (過去 30 日間)
AK
AK 2021 年 5 月 27 日
コメント済み: Jan 2021 年 5 月 28 日
Hello,
I have been trying to create a plot, with an unknown number of lines. Each should be on the same graph, and a different colour. However, I am only getting one line on my graph.
This is my code currently:
y = cell(numFiles,1) ;
x = [30:10:100]
figure();
hold on
for k = 1:numFiles
%Code that generates data
y{k} = [h g f e d c b a ]
plot(x,y{k}, 'Color', [rand,rand,rand])
end
title('SNR / Index')
hold off
What am I doing wrong? Thank you!

採用された回答

Jan
Jan 2021 年 5 月 27 日
x = 30:10:100;
figure();
% axes('NextPlot', 'add'); % Same as: hold on
hold on
for k = 1:8
y{k} = rand(size(x));
plot(x, y{k}, 'Color', rand(1, 3))
end
You see, it works with hold('on') or with creating the axes explicitly also.
Are you sure, that this is your code and there is no cla anywhere?
  5 件のコメント
AK
AK 2021 年 5 月 28 日
Thank you! This worked! I need to use the debugger more often.
Jan
Jan 2021 年 5 月 28 日
The debugger is the best friend of the programmer.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by