Filter löschen
Filter löschen

Problem with appending to assignin

2 Ansichten (letzte 30 Tage)
Matt
Matt am 19 Okt. 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

Antworten (2)

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

Melden Sie sich an, um zu kommentieren.


Matt
Matt am 20 Okt. 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)]

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by