Problem with Array initialization each time (Matlab embedded function)
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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;
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!