Continue simulation: resize workspace variables

Hello!
I have run a simulation for 10.000 increments. Now I want to continue on this simulation so that in total 30.000 increments will be run.
For this purpose I want to use a loop to look at all the workspace variables and preallocate them without losing the older values:
for all variables in the workspace
if size(variable,1)==10000
variable(30000,:)=0
elseif size(variable,2)==10000
variable(:,30000)=0
end
end
How can I do this?
I found the following things that could be an ingredient:
list=who;
size(char(list(1)));

3 件のコメント

Sudarshan Kolar
Sudarshan Kolar 2017 年 2 月 27 日
I understand that you want to append data to your workspace variable after each simulation run.
Are you changing anything in the model between subsequent runs? For example, you run the model for 10 steps, change model parameters etc. and run the model again?
Amy
Amy 2017 年 2 月 28 日
Nothing is changed except for the number of increments that I want to run and the final time that I want to run it.
Sudarshan Kolar
Sudarshan Kolar 2017 年 2 月 28 日
You can write a script that runs the model for 10 increments. Saves the data in an array and re-run the simulation for say 20 increments.
As an example, say my model has a "To workspace" block that logs a variable called "var1" every simulation.
storeData = []; %preallocate this for speed
sim('vdp','StopTime','10');
storeData = [storeData var1];
sim('vdp','StartTime','10','StopTime','20');
storeData = [storeData var1];
sim('vdp','StartTime','20','StopTime','30');
storeData = [storeData var1];
You can also use SimState for this.

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

 採用された回答

Amy
Amy 2017 年 2 月 28 日

0 投票

Thank you for your responses.
I solved my problem by doing the preallocation using A(30000,:)=0 instead of A=zeros(30000,xxx).

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 2 月 27 日

0 投票

1 件のコメント

Amy
Amy 2017 年 2 月 28 日
I don't think that that applies to my question.

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

Amy
2017 年 2 月 24 日

コメント済み:

2017 年 2 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by