user2755399
user2755399

Reputation: 139

matlab, plot multiple matrices different colors

Within my GUI I want to plot multiple matrices on the same plot in different colors. The matrices are being combined from .mat files within different folders so I am currently saving them within a structure. How can I tell the plotter to plot each matrix a different color and symbol? Thanks

Edit:

I was trying to use

plot(1:size(small_group,1),small_group,'.')
set(0,'DefaultAxesColorOrder',[1 0 0;0 1 0]);

However this changed the color for every line. I also haven't worked much with adjusting the symbol yet.

I manually added multiple matrices within the structure by,

plot(small_group_struct(1,2).values)
hold on; plot(small_group_struct(1,1).values)

I was hoping to be able to use the set(0,'DefaultAxesColor', [1 0 0; 0 1 0], ... 'DefaultAxesLineStyleOrder','-|--|:|-.'); to adjust the color and symbol but it is changing the color/symbol for every column not matrix.

Upvotes: 0

Views: 2636

Answers (2)

alonhzn
alonhzn

Reputation: 158

This is the correct way to do it:

aa=gca;
for i=1:N
plot(mat(:,:,i),'color',aa.ColorOrder(aa.ColorOrderIndex,:))
end

it will set the same color to all the lines in the same matrix.

Upvotes: 0

Peter
Peter

Reputation: 14937

Just use the syntax

plot(mat1, 'r');
hold on;
plot(mat2, 'g');

However, instead of hardcoding the values, compute them from your own table:

mystyles = {'r-', 'g:', 'k|'};

plotstyle = mystyles{mod(plotnum, length)+1};
plot(values, plotstyle);

I've used mod to circle back around the beginning. You can use whatever logic you want, including combining different colors and styles with two different pieces of arithmetic.

Upvotes: 1

Related Questions