Hi.
I have written an algorithm that computes an array "b" for each ith iteration [i={1,2,3,4}], and I would like to save those arrays in a structure called "A".
How to save those arrays in the structure "A" where its elements are function of "i", i.e, A = {b1, b2,b3, b4} and to get b1 for instance, one would have to type A.b1.
Regards.

2 comentarios

Stephen23
Stephen23 el 16 de Mayo de 2019
Editada: Stephen23 el 16 de Mayo de 2019
Note that using a non-scalar structure would be more efficient than generating fieldnames.
Indexing is much faster and less buggy than messing around forcing meta-data (i.e. that index) into some fieldnames.
madhan ravi
madhan ravi el 16 de Mayo de 2019
Agree with Stephen.

Iniciar sesión para comentar.

 Respuesta aceptada

madhan ravi
madhan ravi el 15 de Mayo de 2019

0 votos

doc cell2struct

3 comentarios

Abderrahmane DADA
Abderrahmane DADA el 16 de Mayo de 2019
Thanks Madhan for your input, but I would like to get is, at each iteration "i", the array should be saved directly and named after the index "i".
Ex: i=1 => b (n x n) is computed then savedin the strcture A as A.b1.
i=2 => b (n x n) is computed then savedin the strcture A as A.b2
You now what I mean now?
madhan ravi
madhan ravi el 16 de Mayo de 2019
Editada: madhan ravi el 16 de Mayo de 2019
A=struct; % an example
for k=1:5
A.(sprintf('b%d',k))=rand(5);
end
Abderrahmane DADA
Abderrahmane DADA el 16 de Mayo de 2019
Thanks a lot Madhan.
That's exactly what I was looking for.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2017a

Etiquetas

Preguntada:

el 15 de Mayo de 2019

Comentada:

el 16 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by