Problem with appending to assignin

1 次查看(过去 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 CenterFile Exchange 中查找有关 Financial Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by