Get a plot to automatically load different colors using a matrix

3 次查看(过去 30 天)
I am trying to plot 16 different sets of data onto 1 plot, and my adviser suggested concatenating the data I am using (amplitude data) and then when plotting it should load all 16 in different colors automatically. I was able to concatenate the data, but for some reason I can't get it to plot correctly. Here is a snippet of my data below:
load(FILENAME);
respidx = find(n1p2amp > THR_CRIT);
allamp = cat(2, n1p2amp,allamp);
plot (masker*ELEC_SPACE,allamp)%plots amplitude data
xlabel('Masker Electrode (re: electrode spacing)')
ylabel ('Amplitude (mV)');
text(masker(respidx(maxidx))*ELEC_SPACE,n1p2amp(respidx(maxidx)),[num2str(maskch)],...
'VerticalAlignment','middle',...
'HorizontalAlignment','right',...
'FontSize',10)
hold on;
set(gca,'XLim',[0*ELEC_SPACE 16*ELEC_SPACE],'YLim',[-0.1 0.6]);
set(gca, 'XTick',0:4*ELEC_SPACE:16*ELEC_SPACE);
This is all contained within the loop "i" which is essentially numbered 1:16. I have a 16x16 matrix for each subject, so the x-axis has 16 points with each point containing 16 data points, if that makes sense. I just don't want to have to manually tell this to do 16 different colors. Thanks!

采纳的回答

Mike Garrity
Mike Garrity 2014-10-2
I think your advisor is just referring to the fact that if you give plot a YData array which is an MxN array, then it will plot them as M curves and give each one its own color.
Consider this example:
d = gallery('moler',16,.5); % an interesting 16x16 matrix
Executing this:
plot(1:16,d);
creates the same thing as:
hold on
for i=1:16
plot(1:16,d(i,:));
end
and it also gives each of the curves a different color.
BTW, you can also get the second example to generate different colors by using "hold all" instead of "hold on".
Also, the plot command pulls its colors from the ColorOrder property of the axes rather than the colormap. The colormap is only used by objects which have CData, such as surface or image.
  1 个评论
Lindsay
Lindsay 2014-10-2
Mike, thank you so much. I will try this later today and let you know how it went. I'm still relatively new to Matlab so your instructional response helps a great deal!

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2014-10-2
The easiest way is to specify the color when you plot. If you don't you get the default colors. Maybe you'd be interested in my ColorOrder demo where you can alter the default colors.
  3 个评论
Image Analyst
Image Analyst 2014-10-2
You're welcome. Maybe you could "Vote" for the answer even if it didn't earn your "Acceptance", if it at least you learned something from it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by