Problem with Array initialization each time (Matlab embedded function)

Hello, I'm quite new to matlab, and try to code in c-style. My problem is, I have a embedded matlab function, which reads the error values and the index from input and update in the array. This looks like so..
function u1 = EvaluatePattern(HopSeq,Dis,Erri,ErrV,En)
ErrpatternArray= [1,1,1,1,1,1,1,1,1,1,1];
ErrpatternArray(Erri) =ErrV;
the Erri and ErrV will be the random values and will be updated each time this embedded block run. I just tried debugging, and found that each time "ErrpatternArray" is initiated and the whatever the update i had made in the previous is not stored. I just want to declara and initiate this array only at the very begining and keep updating the values. I couldn't find any solution. Can anybody please help me out.!!! - regards Aravind

 채택된 답변

you can either
1. Make your variable persistent
function u1 = .....
persistent ErrpatternArray
if isempty ( ErrpatternArray );
ErrpatternArray = Intialvalues;
end
....your code
2. Initialise it in the calling function
ErrpatternArray = Initialvalues;

댓글 수: 1

Wow, Robert, that was so instant reply from you, and the first one works.!! Thanks a ton Pal.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by