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

7 vues (au cours des 30 derniers jours)
SyukriY
SyukriY le 9 Déc 2016
Commenté : Kerry Schutz le 13 Nov 2020
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 commentaires
SyukriY
SyukriY le 9 Déc 2016
Modifié(e) : SyukriY le 9 Déc 2016
Note that,
I'm using MATLAB function block to code a function in simulink.
Kerry Schutz
Kerry Schutz le 13 Nov 2020
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

Connectez-vous pour commenter.

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by