フィルターのクリア

Problem with appending to assignin

2 ビュー (過去 30 日間)
Matt
Matt 2011 年 10 月 19 日
Hi,
I have this line of code:
assignin('base',char(regexprep(TXTFilenameMAINTENANCE(j,1),'[^\w'']','')),polyfit (X,Y,1));
which is inside a loop
Which puts the polyfit of X & Y into a variable called 'Ballast_Renewal', this line works perfectly for the first iteration in the loop. For the following iterations it just keeps overwriting the first row in the variable 'Ballast_Renewal'.
my knowledge of appending to a Matlab variable are limited to the basic methods: x(end+1)=2; x=[x; 2];
Non of which I can get to work for my particular problem, anyone know why?
Thanks in advance

回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 10 月 19 日
Ouch!
Please consider using dynamic structure field names instead.
  1 件のコメント
Matt
Matt 2011 年 10 月 20 日
Hi, thanks for the tip. I'm newish to matlab and didn't know about structures.
I've tried this:
A(j,1) = regexprep(TXTFilenameMAINTENANCE(j,1),'[\W'',\d]','')
s.(A{j,1}) = polyfit (X,Y,1)
But I want to append each time, i've tried something like this and i get the following error:
??? s.(A{j,1} =[A{j,1}; polyfit (X,Y,1)]
|
Error: The expression to the left of the equals sign is not a valid target for an assignment.
any ideas?

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


Matt
Matt 2011 年 10 月 20 日
Solved:
A(j,1) = regexprep(TXTFilenameMAINTENANCE(j,1),'[\W'',\d]','') s.(A{j,1}) = polyfit (X,Y,1)
then to append:
s.(A{j,1}) =[s.(A{j,1}); polyfit(X,Y,1)]

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by