Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
changing color plot in a looped figure plotting

Subject: changing color plot in a looped figure plotting

From: Gael crevoise

Date: 23 Nov, 2012 10:52:07

Message: 1 of 2

Hello,

I have a question about plotting while looping to get information from an excel file

I have the following script:
for i=3:6:225
x=xlsread('test.xlsx','Sheet1',['B' int2str(i) ':JB' int2str(i)]);
y=xlsread('test.xlsx','Sheet1',['B' int2str(i+1) ':JB' int2str(i+1)]');
plot(x,y)
hold on
end
hold off

I wish to have different color for different part of the plot. For example, it could be great that all data from 3,21,39....are plotted in green, while the one 9,27,45.... are in blue, and the data 15,33,51....are plotted in red.

Is it possible to make such a things?
Thanks a lot for your help

Subject: changing color plot in a looped figure plotting

From: Sadik

Date: 24 Nov, 2012 14:24:08

Message: 2 of 2

You could do:

figure
hold on
for i=3:6:225
    x=xlsread('test.xlsx','Sheet1',['B' int2str(i) ':JB' int2str(i)]);
    y=xlsread('test.xlsx','Sheet1',['B' int2str(i+1) ':JB' int2str(i+1)]');
    if mod(i,18)==3 % 3, 21, ...
        plot(x,y,'g')
    elseif mod(i,18)==9 % 9, 27, ...
        plot(x,y,'b')
    else % that is, if mod(i,18)==15 % 15, 33, ...
        plot(x,y,'r')
    end
end
hold off

Best.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us