Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab-绘制两个结构之间的平均值?_Matlab_Plot_Average - Fatal编程技术网

Matlab-绘制两个结构之间的平均值?

Matlab-绘制两个结构之间的平均值?,matlab,plot,average,Matlab,Plot,Average,我刚接触Matlab,我认为这是一个非常基本的问题 我有两个阵列: tst ans = 0 0 0.2500 0.2500 0 0 0 0 prp ans = 0 0 0 0.5333 0.0333 0.0333 0.1667 0.0667 我想在同一个图(作为一条线)上绘制这

我刚接触Matlab,我认为这是一个非常基本的问题

我有两个阵列:

 tst

  ans =

          0         0    0.2500    0.2500         0         0         0         0

 prp

    ans =

          0         0         0    0.5333    0.0333    0.0333    0.1667    0.0667

我想在同一个图(作为一条线)上绘制这两个图之间的平均值。最好的方法是什么?

我通常会这样做:

# Plot figure
plot(...);

# Calculate the average
avg = mean(tst);

# Add a line to the figure
line(xlim(), [avg avg]);
# Calculate average between arrays
avg = mean([tst;prp]);

# Plot all 3 lines at once
plot([tst;prp;avg]');
prp
重复上述步骤。根据文档,可以根据需要设置线条的样式

请注意,如果要更改xlimit(
hold
ing并绘制其他内容,等等),则应在结束时执行此操作,因为这取决于
xlim()

编辑

我可能误解了你的问题。上述代码将在阵列中点的平均值处绘制一条水平线
tst

相反,如果您想要一个点为两个阵列平均值的线图,则需要类似以下内容:

# Plot figure
plot(...);

# Calculate the average
avg = mean(tst);

# Add a line to the figure
line(xlim(), [avg avg]);
# Calculate average between arrays
avg = mean([tst;prp]);

# Plot all 3 lines at once
plot([tst;prp;avg]');

是的,就是这样。谢谢我会尽快接受答案,所以请允许我)