A basic plotting problem in a for loop

2 ビュー (過去 30 日間)
Christian
Christian 2017 年 2 月 2 日
コメント済み: Christian 2017 年 2 月 2 日
Hello everybody,
I have a Problem which seems to be very stupid and I apologize for my question in advance!
I have a for loop to plot all of the results of a former loop. Now I would like to change the color of the plots to grey. Basically this is not a big deal if you have x and y for example. In my case I plot data1 vs data2. Both of them have the same size. If I use a colormap or something like 'color', [1 1 1] I always get the error that the vectors must be the same size. How can I fix this?!
for d=1:numel(Filename)
figure(1);
hold on
plot(Data_1(:,d), Data_2(:,d), 'Color', [1 1 1])
axis([-25 25 -20 25])
axis equal
end
Thank you!
Cheers
Christian
  3 件のコメント
Stephen23
Stephen23 2017 年 2 月 2 日
@Christian: please edit your question and give us the complete error message. This means all of the red text.
Christian
Christian 2017 年 2 月 2 日
Hey Adam and Stephan,
yes, the vectors are exactly the same size. It works now, I think there was a Syntax error somewhere :)

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

採用された回答

tafteh
tafteh 2017 年 2 月 2 日
Hi Christian,
(a) "(There's) no such thing as a stupid question," read more at link !
(b) Unless the vectors Data_1(:,d) and Data_2(:,d) are not the same size, you should not get an error.
(c) using the argument 'Color' with the value of [1 1 1], results in plotting all the lines in white which is the same as the white background of plotting environment. You may want to change that :)
(d) I wrote the following code trying to mimic what you want to do:
first I generate two 2d matrices, a and b with same size:
if true
a = rand(3, 4); b = rand(3, 4);
end
and then I use your code to plot them:
if true
for d=1:size(a, 2) % mimic the numel(Filename) in your code.
figure(1);
hold on
plot(a(:,d), b(:,d), 'Color', [.1 .1 .1])
axis([-25 25 -20 25])
axis equal
end
end
it works for me. You may want to change the code based on your need.
cheers,
  1 件のコメント
Christian
Christian 2017 年 2 月 2 日
Thank you very very much! Now it works!
Even though I do not know, what was my fault, maybe just a Syntax issue.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by