Problem with Array initialization each time (Matlab embedded function)

3 ビュー (過去 30 日間)
Aravind
Aravind 2011 年 7 月 10 日
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

採用された回答

Robert Cumming
Robert Cumming 2011 年 7 月 10 日
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 件のコメント
Aravind
Aravind 2011 年 7 月 10 日
Wow, Robert, that was so instant reply from you, and the first one works.!! Thanks a ton Pal.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by