A basic plotting problem in a for loop

2 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 2 Feb 2017
@Christian: please edit your question and give us the complete error message. This means all of the red text.
Christian
Christian on 2 Feb 2017
Hey Adam and Stephan,
yes, the vectors are exactly the same size. It works now, I think there was a Syntax error somewhere :)

Sign in to comment.

Accepted Answer

tafteh
tafteh on 2 Feb 2017
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 Comment
Christian
Christian on 2 Feb 2017
Thank you very very much! Now it works!
Even though I do not know, what was my fault, maybe just a Syntax issue.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!