Clear Filters
Clear Filters

Problem with appending to assignin

2 views (last 30 days)
Matt
Matt on 19 Oct 2011
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

Answers (2)

Walter Roberson
Walter Roberson on 19 Oct 2011
Ouch!
Please consider using dynamic structure field names instead.
  1 Comment
Matt
Matt on 20 Oct 2011
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?

Sign in to comment.


Matt
Matt on 20 Oct 2011
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)]

Categories

Find more on Loops and Conditional Statements 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!