Logical indexing of nonscalar structures

4 visualizaciones (últimos 30 días)
Octavian
Octavian el 30 de En. de 2021
Respondida: Jan el 30 de En. de 2021
Dear All,
I have a nonscalar nested structure s of length n, I need to index field e in s (s.a.b.c.d.e). I can do it with a loop,
for i = 1:length(s)
s(i).a.b.c.d.e = g(x(i));
end
where x is a logical array. I wanted to know if it is possible to use x for indexing s(x).a.b.c.d.e = g(x); I have lots of such assigments in my code, so it is important to know. For now, I get a dot indexing error when trying the logical indexing.
Thank you,
O

Respuestas (2)

Matt J
Matt J el 30 de En. de 2021
No, it is not possible.

Jan
Jan el 30 de En. de 2021
There is no abbreviation. There is no method for vectorizing the access of nested struct arrays.
Maybe a tiny acceleration:
gx = g(x);
for i = 1:length(s)
s(i).a.b.c.d.e = gx(i);
end

Categorías

Más información sobre Structures 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