绘制无循环的单元格阵列 [英] Plot cell array without loop

查看:70
本文介绍了绘制无循环的单元格阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

SimRun = 0
Count = 0

for b = 1:0.5:3000
.
.
.
.
    Count = Count + 1;
    ArrayT(Count) = Time;
    ArrayTgo(Count) = tgo;
    ArrayY(Count) = Y;
    ArrayYD(Count) = YD;

end

SimRun = SimRun  + 1;
MAT_ArrayT{SimRun,:} = ArrayT;
MAT_ArrayTgo{SimRun,:} = ArrayTgo;
MAT_ArrayY{SimRun,:} = ArrayY;
MAT_ArrayYD{SimRun,:} = ArrayYD;

如您所见,我有2个for循环.从内部循环中,我收到一个向量,从外部循环中,我最终收到一个单元格数组,其中每个单元格都是一个向量.

As you can see, I have 2 for loops. From the inner loop I receive a vector and from the outer loop I receive in the end a cell array where each cell is a vector.

现在,我想绘制单元格阵列以绘制大约6000条线,我这样做如下:

Now, I had like to plot the cell array to plot basically around 6000 lines and I did it as follows:

for i = 1:SimRun

    figure(1)
    hold on
    plot(MAT_ArrayT{i,:},MAT_ArrayY{i,:})

    figure(2)
    hold on
    plot(MAT_ArrayT{i,:},MAT_ArrayYD{i,:})

end

但是,此解决方案需要花费很多时间来绘制所有线条.

However this solution takes pretty much time to draw all the lines.

是否有更好的解决方案来存储线"并将其全部绘制在最后一击中?

Is there any better solution to store "lines" and plot all of them in one hit at the end?

谢谢.

推荐答案

plot命令采用矩阵并将每列绘制为单独的行.假设单元格数组中有列向量,并且它们的长度都相同,则可以执行以下操作:

The plot command takes a matrix and plots each column as a separate line. Assuming you have column vectors in your cell arrays, and they're all the same length, you can do this:

x = [MAT_ArrayT{:}];
y = [MAT_ArrayY{:}];
plot(x,y)

更好的方法是将这些向量存储在数字矩阵的开头,因此您无需制作多余的副本.

Even better would be to store those vectors in a numeric matrix to start with, so you don't need to make the extra copy.

这篇关于绘制无循环的单元格阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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