Looping a simulink model for multiple time-input

Hello, I am trying to run a simple simulink model but i would like to automate the input from a m.file. It should run 201 times since there are 201 columns of time-input and report the output into a matrix. Is there any way to do this? thank you
load F.mat % attached
p=1:201 % number of columns
Force=zeros(512,201)
for n=1:p
Force=F(:,p)
sim('test') % below
end

 採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 9 月 2 日

0 投票

load F.mat % attached
% a matrix of F is loaded, it is a 512x201 double array
p=size(F,2) % number of columns
for n=1:2 % for testing first, change it to be "for n=1:p" later
Force=F(:,n)
sim('test') % below
end

3 件のコメント

Komal Rajana
Komal Rajana 2020 年 9 月 2 日
編集済み: Komal Rajana 2020 年 9 月 2 日
Thank you so much.
But i think, I am overwriting the output results after each column irerations? Is there a way i can save the results into a matrix array? thanks
load F.mat % % a matrix of F is loaded, it is a 512x201 double array
Tin=linspace(0,30,512)'; % time steps 30 seconds
SimT=[Tin F]
p=size(SimT,2) % number of columns
for n=2:3 % for testing first, change it to be "for n=1:p" later
Force=[Tin SimT(:,n)]
sim('test',Tin) % below
end
Fangjun Jiang
Fangjun Jiang 2020 年 9 月 2 日
Not like that. p would be 202 because SimT has 202 columns.
load F.mat % % a matrix of F is loaded, it is a 512x201 double array
p=size(F,2) % number of columns
Tin=linspace(0,30,p)'; % time steps 30 seconds
Results=cell(1,p);
for n=1:3 % for testing first, change it to be "for n=1:p" later
Force=[Tin F(:,n)]
Results{n}=sim('test',Tin) % below
end
Komal Rajana
Komal Rajana 2020 年 9 月 2 日
Thank you
I got the code to work. This is final code.
load F.mat % % a matrix of F is loaded, it is a 512x100 double array
p=size(F,2) % number of columns
Tin=linspace(0,30,512)'; % time steps 30 seconds
Results=cell(1,p);
for n=1:p % for testing first, change it to be "for n=1:p" later
Force=[Tin F(:,n)]
Results{n}=sim('test',Tin) % below
end

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by