フィルターのクリア

How to save all the simulated iterations (output of loop) togather?

1 回表示 (過去 30 日間)
Nisar Ahmed
Nisar Ahmed 2022 年 9 月 9 日
コメント済み: William Rose 2022 年 9 月 10 日
Hi,
This is my code and each and five out parameters are vp0, vs0, rh0, qp0, qs0 each of size (115*50). I want to save out put vp0, vs0, rh0, qp0, qs0 as of size (115 50) but instead each time I have to change k as from 1 then 2, 3 and so on...
Simply means, each time I have to save individual vp0(1), vp0(2), vp0(3) and so on... How I can save vp0(115*5) all togather?
figure(3);
for k=1:50
print k
msim = mvnrnd(Mu_m, Sigma_m)';
msimlogs = reshape(msim,nt,5);
h1=subplot(1,5,1); hold on; plot(msimlogs(:,1),t); hold on; plot(vp0,t,'k','LineWidth',1.5); title('Simulated V_P'); ylim([1852 1965]);
h2=subplot(1,5,2); hold on; plot(msimlogs(:,2),t); hold on; plot(vs0,t,'k','LineWidth',1.5); title('Simulated V_S'); ylim([1852 1965]);
h3=subplot(1,5,3); hold on; plot(msimlogs(:,3),t); hold on; plot(rho0,t,'k','LineWidth',1.5); title('Simulated Rho'); ylim([1852 1965]);
h4=subplot(1,5,4); hold on; plot(msimlogs(:,4),t); hold on; plot(qp0,t,'k','LineWidth',1.5); title('Simulated Q_P'); ylim([1852 1965]);
h5=subplot(1,5,5); hold on; plot(msimlogs(:,5),t); hold on; plot(qs0,t,'k','LineWidth',1.5); title('Simulated Q_S'); ylim([1852 1965]);
msimsave(:,:,k) = msimlogs;
end
set(h1,'YDir','Rev'); set(h2,'YDir','Rev'); set(h3,'YDir','Rev'); set(h4,'YDir','Rev'); set(h5,'YDir','Rev');
vp0 = msimsave(:,1,3); vs0 = msimsave(:,2,3); rho0 = msimsave(:,3,3); (can I get here all k, instead 1 array)
qp0 = msimsave(:,4,3); qs0 = msimsave(:,5,3);
save Initial_model.mat vp0 vs0 rho0 qp0 qs0;
k --- is plotted below

採用された回答

William Rose
William Rose 2022 年 9 月 9 日
Make a 3D array.
vp0all=zeros(115,50,5);
for i=1:5
vp0=rand(115,50); %compute vp0
vp0all(:,:,i)=vp0; %save the currnt vp0 in 3D array
end
Try it.
  4 件のコメント
Nisar Ahmed
Nisar Ahmed 2022 年 9 月 10 日
Thanks, now it is working, Yes this mean that each of vp0, vs0, rho0... is a matrix with dimensions 115 by 50.
Thank you again
William Rose
William Rose 2022 年 9 月 10 日
@Nisar Ahmed, you're welcome. Good luck with your work.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by