how to store some of the values of a simulation while running?

2 ビュー (過去 30 日間)
K G
K G 2019 年 7 月 19 日
コメント済み: K G 2019 年 7 月 20 日
I want to store my values while simulation running under a condition to use it before the simulation time end. I only need values in my vector and no 'nan' because i need to do a calculation on it.
function u_out = fcn(statusFlag,u_in)
u_out=zeros(100000,1);
persistent n
if isempty(n)
n = 0;
end
n=n+1;
persistent u_data
if isempty(u_data)
u_data = 0;
end
if statusFlag == 4
u_data=u_in;
u_out(n+1)=u_data;
elseif statusFlag~=4 && statusFlag~=5
u_data=nan;
end
end

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 7 月 19 日
編集済み: KALYAN ACHARJYA 2019 年 7 月 19 日
You can do it as follows
u_out=zeros(100000,1);
j=1;
for i=1:length
condition check, if yes
u_data(j)=....
j=j+1
else
%no
end
end
Now all simulation values are save in u_data as array, you can call it when it is required.
  3 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 7 月 19 日
編集済み: KALYAN ACHARJYA 2019 年 7 月 19 日
Where is your main script, where you are calling this function?
You are trying to save u_data values, right?
K G
K G 2019 年 7 月 20 日
as the simulation is running

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

その他の回答 (1 件)

K G
K G 2019 年 7 月 19 日
I m tring to save the u_in values in u_out , the function is in simulink model

カテゴリ

Help Center および File ExchangeString についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by