当我在MATLAB中循环绘图时如何赋予不同的颜色? [英] How to give different colors when I loop for plot in MATLAB?

查看:711
本文介绍了当我在MATLAB中循环绘图时如何赋予不同的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据说X的大小为(100,2).该X由10个类别(10个一组)的数据组成.现在,我想查看每个类别的数据中的模式.为此,我需要为每个类别分配不同的颜色.我试图循环而不是做10个不同的情节.我尝试了以下.

I have some data say X with size (100,2). This X is composed of data for 10 categories (set of 10). Now I would like to look the pattern in the data for each category. For this I need to have different colors assigned to each category. I am trying to loop instead of doing 10 different plots. I tried the below.

hold on
for i=1:10:100
   plot(X(i:i+9,1),X(i:i+9,2),'.')
end
hold off

这给了我一个相同颜色的情节.如何为不同的范围分配不同的颜色?

This gave me a plot with same color. How can I assign different colors for different range?

推荐答案

最简单的解决方案是将hold on替换为hold all.

The easiest solution is to replace hold on by hold all.

如果您希望获得更多控制,则必须手动定义生产线规格(更多信息

If you want more control you have to manually define your line specifications (more info here) and then pass them to plot:

linespec = {'b.', 'r-', 'g--o'}; % define your ten linespecs in a cell array
hold on
for i=1:10:100
   plot(X(i:i+9,1),X(i:i+9,2),linespec{i})
end
hold off

这篇关于当我在MATLAB中循环绘图时如何赋予不同的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆