为什么对于不同的图形表示,我的图无法循环工作? [英] Why my plot is not working in loop for different graph representations?

查看:108
本文介绍了为什么对于不同的图形表示,我的图无法循环工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个矩阵容量",我想绘制它的行,为此,我使用了一个循环,我的代码是

I have a matrix 'capacity' and I want to plot its row and for that I have used a loop, my code is

for j_1=1:8    
plotStyle = {'k -','r +','g *','b.','y o','r--','b d','g s'};   
hold on;
plot(x_1,capacity(j_1,:),plotStyle(j_1));
end
hold off;

x_1只是x轴,x_1中的元素数等于容量的列数.但是我收到错误消息:

x_1 is just the x axis, the number of elements in x_1 is equal to the number of columns of capacity.But I am getting error as:

使用绘图错误

无效的第一个数据参数

variableDiffusioncofficient(错误扩散系数)错误(第124行)

图(x_1,容量(j_1,:),plotStyle)

推荐答案

您要做的就是在绘图调用中用花括号替换圆括号,即

all you need to do is replace the round braces by curly braces in the call to plot, i.e.

plot(x_1,capacity(j_1,:),plotStyle{j_1});

或者,您可以将颜色和线条样式分开,然后以这种方式进行调用.当您制作更大的图并希望通过颜色和线型的组合以不同的方式循环时,这可能会很方便.

Alternatively, you could separate the color and linestyle and make the call this way. This might be convenient when you make even larger plots and want to loop in different ways through the combinations of colors and linestyles.

capacity = rand(8,8);     % test data for a workable example
x_1 = 1:8;

for j_1=1:8    
linestyle = {'-','+','*','.','o','--','d','s'};   
color = {'k','r','g','b','y','r','b','g'};   
hold on;
plot(x_1,capacity(j_1,:),'color',color{j_1},'linestyle',linestyle{j_1});
end
hold off;

这篇关于为什么对于不同的图形表示,我的图无法循环工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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