How can I used 'save()' command in matlab function block?

24 次查看(过去 30 天)
Hi, everyone. I really need everyone help. I can't used 'save()' command in matlab function block. Do anyone know? and how can I change the 'save()' command in the matlab function block?
function [DayOfOvule,Dmax,CycleLength] = detection(dataB,dataA,limit,CL)
%#codegen
A = dataA;
B = dataB;
fileD = 'difference.txt';
if (A > limit) && (B < limit)
D = A - B;
save(fileD, 'D');
elseif (A > limit) && (B > limit)
%startCountDown
else
end
CycleLength = CL;
S = load(fileD, 'D');
Dmax = max(S.D);
DayOfOvule = 13;
end
end
Does matlab can hold a value? For example, I have my data in timeseries and I want to calculate the differences between each data. Then, from differences I want to find the largest value of the different.
#credit to Walter Roberson for teach me something about delay.
%
  5 个评论
SyukriY
SyukriY 2016-12-9
编辑:SyukriY 2016-12-9
Note that,
I'm using MATLAB function block to code a function in simulink.
Kerry Schutz
Kerry Schutz 2020-11-13
You'll need to use a file I/O function that is supported for code generation. Two examples of that would be fwrite, for binary files, and fprintf, for text files.
These functions, while they work, are still not as convenient as using save due to the overhead associated with the particulars of using lower-level file I/O functions.
You might consider a different approach to saving data in your Simulink model that originates inside a MATLAB Function block. You can try outputting the data back onto a Simulink output port and then using the To File block to save the data to a .mat file. That might be cleaner in the end.
And yes, I realize this is almost 4 years after you submitted your question but I hope it helps someone out there.
Kerry

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by