Plotting Problems: Same Colors
Plotting Problems: Same Colors
(OP)
Hi,
I've coded a few lines and I have some problems.
Please take a look...maybe you know the solution.
At the bottom you will find my question.
I work with Matlab 6 so I specify the path before I run the program.
% Calcualtion
% Name of files to "load"
praefix = ['STC'];
suffix = ['.txt'];
% Number of files
Start = 0;
End = 5;
counter = 1;
for i = Start:End
istr = num2str(i);
if i < 10
NameAlmost = [praefix,'00',istr,suffix];
elseif i > 99
NameAlmost = [praefix,istr,suffix];
else
NameAlmost = [praefix,'0',istr,suffix];
end
NameFinal = char(NameAlmost);
% Open files
Matrix = dlmread(NameFinal,',',5,0);
% Defining x and y
x(1:length(Matrix),counter) = 10^6.*Matrix(:,1);
y(1:length(Matrix),counter) = 24.*Matrix(:,2);
plot(x(1:length(Matrix),1),y(1:length(Matrix),counter))
hold on
counter = counter + 1;
end
Question: When I run this program Matlab plots all lines in one color
blue(!). Why?
What do I have to do so that I get different colors with a correct number of sources in the legend?
'cause I've already modified lots of things but when I got different colors in the plot the source data files in the legend (edit-show legend) missmatch with the lines drawn.
Please help me...I'm looking for the solution for ages.
Bye
I've coded a few lines and I have some problems.
Please take a look...maybe you know the solution.
At the bottom you will find my question.
I work with Matlab 6 so I specify the path before I run the program.
% Calcualtion
% Name of files to "load"
praefix = ['STC'];
suffix = ['.txt'];
% Number of files
Start = 0;
End = 5;
counter = 1;
for i = Start:End
istr = num2str(i);
if i < 10
NameAlmost = [praefix,'00',istr,suffix];
elseif i > 99
NameAlmost = [praefix,istr,suffix];
else
NameAlmost = [praefix,'0',istr,suffix];
end
NameFinal = char(NameAlmost);
% Open files
Matrix = dlmread(NameFinal,',',5,0);
% Defining x and y
x(1:length(Matrix),counter) = 10^6.*Matrix(:,1);
y(1:length(Matrix),counter) = 24.*Matrix(:,2);
plot(x(1:length(Matrix),1),y(1:length(Matrix),counter))
hold on
counter = counter + 1;
end
Question: When I run this program Matlab plots all lines in one color
blue(!). Why?
What do I have to do so that I get different colors with a correct number of sources in the legend?
'cause I've already modified lots of things but when I got different colors in the plot the source data files in the legend (edit-show legend) missmatch with the lines drawn.
Please help me...I'm looking for the solution for ages.
Bye





RE: Plotting Problems: Same Colors
The reason for your problem is that every loop step you are creating a new single line plot. By default MATLAB draws the first curve in blue.
You have two possibilities:
1) Create your result matrix Y(length(Matrix),length(counter)) and expand x to be of the same size using 'repmat' function to get X.
Than use plot(X,Y) once outside the loop.
This is easy if all your data file are of the same length.
2) Create a string of color names using MATLAB notation:
C=['r' 'g' 'b' 'c' 'm' 'k' 'y'];
Then within the loop add the color as one more parameter in the plot command.
plot(x,y,C(counter)); % index may be counter+1 if counter starts from zero.
This is easy if you do not have too many plots. Otherwise you have to define C in a more sophisticated way (e.g. using colorbar).
Joe
----------------------------------------------------------------------------------
BSTEX - Equation viewer for MATLAB is cross-platform
http://www.geocities.com/bstex2001