Local functions. Appending results of looping to previous variable; creating separate variable for each loop.
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a local function that returns two variables, say [icke,data]=localfunction(x). I am using a for loop to apply the local function several times.
for i=1:10
[icke,data]=localfunction(x)
end
Want I want to do is for each loop of the local function for icke, I want the result to be appended to the bottom of the previous icke. Right now the above removes and replaces the previous each time.
For the second variable data, I would like a new variable to be created for each one, ideally, so we have data1, data2, ..., data10.
0 comentarios
Respuestas (1)
Star Strider
el 21 de Nov. de 2018
Editada: Star Strider
el 21 de Nov. de 2018
Subscript the outputs. If they are scalars, use:
for i=1:10
[icke(i,:),data(i,:)]=localfunction(x)
end
If they are vectors, or if there are different size outputs, use cell arrays:
for i=1:10
[icke{i},data{i}]=localfunction(x)
end
Please never name variables dynamically. Simply refer to them by thier subscripts.
Also, you may want to subscript the inputs as well:
for i=1:10
[icke(i,:),data(i,:)]=localfunction(x(i))
end
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!