×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Plotting Problems: Same Colors

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

RE: Plotting Problems: Same Colors

Hi,
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources