Plot a structure array without a loop

5 visualizaciones (últimos 30 días)
Fawad Farooq Ashraf
Fawad Farooq Ashraf el 2 de Ag. de 2022
Respondida: Fawad Farooq Ashraf el 2 de Ag. de 2022
I ran a Monte-Carlo with 300 simulation runs and I stored the output data for each run in a structure as
DATA(i).x = outputX;
DATA(i).y = outputY;
.Now I want to plot the data in a figure for all iterations without iterating through a loop. For now, I'm using
figure(1);hold on;grid on;box on;
for i = 1:n
plot(DATA(i).x,DATA(i).y,'.-')
end
hold off;
Is it possible to plot all the data as
plot(DATA(:).x,DATA(:).y,'.-');
or do I have to use commands like struct2cell and then cell2mat for this?

Respuesta aceptada

Fawad Farooq Ashraf
Fawad Farooq Ashraf el 2 de Ag. de 2022
I think I've found the answer to this myself.
figure(1);hold on;grid on;box on;
p = arrayfun(@(a) plot(a.x,a.y,'.-'),DATA);
This works quite well and also faster than plotting inside a for loop.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by