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 CenterFile Exchange에서 Colorbar에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by