Problem with Array initialization each time (Matlab embedded function)

3 views (last 30 days)
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

Accepted Answer

Robert Cumming
Robert Cumming on 10 Jul 2011
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 Comment
Aravind
Aravind on 10 Jul 2011
Wow, Robert, that was so instant reply from you, and the first one works.!! Thanks a ton Pal.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!