Saving a matrix variable in Embeded Matlab Function

Hi everyone, I use Embeded Matlab function block in simulink.I have a matrix variable inside this block,which should be saved in every step ,and be used for next step.Since 'save' command is disabled in Matlab function block,Which block or command should i use? I know about memory block or data store memory,but the first one doesnt have a sample time and second one cant store a matrix! thanks in advance

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 13일
편집: Azzi Abdelmalek 2014년 1월 13일
You can declare your matrix as persistent
Example
function y=fcn(u)
persistent M
if isempty(M)
M=M0 % Define initial condition for your matrix M
end
%do

댓글 수: 2

Sarah commented
This is the function that i wrote in embeded matlab function block:
function [ y_hat,teta1,P1] = fcn(u1, u2, u3, u4, u5, y, P, teta)
persistent P
persistent teta
Phi=[u1 u2 u3 u4]';
dP=zeros(4,4);
dP(3,4)=-u3; dP(4,3)=-u3; dP(4,4)=u5;
y_hat=teta(1:3)'*[u1 u2 u3]'; error=y-y_hat; beta=0.055;
Pdot=beta*P-P*(Phi*Phi'-error*dP)*P
P1=Pdot*0.01+P;
tetaDot= P*error*Phi;
teta1=tetaDot*0.01+P;
This error was ocurred:
The PERSISTENT declaration must precede any use of the variable P.
Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 13일
편집: Azzi Abdelmalek 2014년 1월 13일
It's not clear how P and teta are updated. and if they are in the input argument , they can't be declared as persistent

댓글을 달려면 로그인하십시오.

Sarah Miller
Sarah Miller 2014년 1월 13일

0 개 추천

Yes,they are in the input argument,So would you pls tell me what can i do?

댓글 수: 1

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 13일
편집: Azzi Abdelmalek 2014년 1월 13일
Sarah, if you want to add a comment. Please click on comment on this answer do not add answers

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interactive Model Editing에 대해 자세히 알아보기

태그

질문:

2014년 1월 13일

편집:

2014년 1월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by