# How is it possible to plot the average of a vector that has a different size in each iteration?

1 ビュー (過去 30 日間)
Waseem AL Aqqad 2021 年 6 月 3 日

I'm trying to obtain a plot of M by averaging 10 simulations of M, but the problem is that it has a different size in each run.
Of course I'm getting this error message:
Unable to perform assignment because the size of the left side is 1-by-17 and the size of the right side is 1-by-15
for jj = 1:10
t = 2;
while M(t-1)- M(t)~=0
t = t+1;
end
Mavg(jj,:)=M;
end
Mavg = mean(Mavg,1);
figure(1)
plot(1:length(Mavg(1:end-1)),Mavg(1:end-1));
Thank you.

サインインしてコメントする。

### 採用された回答

KSSV 2021 年 6 月 3 日
Mavg = zeros(10,1) ;
for jj = 1:10
t = 2;
while M(t-1)- M(t)~=0
t = t+1;
end
Mavg(jj)=mean(M);
end
plot(Mavg)
##### 11 件のコメント表示非表示 10 件の古いコメント
Waseem AL Aqqad 2021 年 6 月 4 日
So basically, the x-axis represents the time which is also the no. of columns of M and the y-axis represents the cumulative number of packets of information fails in each time step. And the total no. of packets is 5000, so the curve eventually should stop once it reaches 5000.

サインインしてコメントする。

### その他の回答 (1 件)

SALAH ALRABEEI 2021 年 6 月 5 日
Finding the minimum length ( assum it is 10) , then use the moving average ( smoothing) all the other results to get all of them with same length (10). In short, shorten all the arrays to one fixed length by averaging them using smooth function.

サインインしてコメントする。

### カテゴリ

Find more on Annotations in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!