필터 지우기
필터 지우기

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

조회 수: 8 (최근 30일)
SyukriY
SyukriY 2016년 12월 9일
댓글: Kerry Schutz 2020년 11월 13일
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