且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Matlab中使用For循环进行绘图

更新时间:2023-02-26 16:38:07

将for循环中的数据输出收集到单个数组中,然后使用该函数调用一次plot.可以在您的for循环中插入以下内容:

Gather the data output in your for loop into a single array, then call plot once with that. The following can be inserted in place of your for loop:

timevect = 213:313;
yvect(1, length(timevect)) = 0;
for ii = 1:length(timevect)
    ti = timevect(ii);
    a= @(t) (h*pi*D*(t-ti))+(o*e*D*pi*(t^4 - ti^4))-((u*D*G)+(I^2*r));
    t = fzero(a,0);
yvect(ii) = t;
end
plot(timevect, yvect)

请注意,现在图中坐标轴的时间数据在 vector 中,ydata也在.您是在for循环中绘制标量.

Note that now the time data for your axis in the plot is in a vector and the ydata too. You were plotting scalars in a for loop.