Borrar filtros
Borrar filtros

Problem with appending to assignin

2 visualizaciones (últimos 30 días)
Matt
Matt el 19 de Oct. de 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

Respuestas (2)

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

Iniciar sesión para comentar.


Matt
Matt el 20 de Oct. de 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)]

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by