Plotting data from struct

15 vues (au cours des 30 derniers jours)
Leandro Seguro
Leandro Seguro le 1 Jan 2021
Modifié(e) : dpb le 1 Jan 2021
Hi all,
I am trying to plot the data from the ''Cost'' column located in the pop struct which I have attached, where each cell in that column contains an x and y value for what I need to plot.
I've been trying to extract the data but I can't seem to figure it out. Any help would be appreciated!
Many thanks in advance.

Réponse acceptée

dpb
dpb le 1 Jan 2021
Modifié(e) : dpb le 1 Jan 2021
Couple ways of many...
XY=reshape([pop.Cost],2,[]).';
plot(XY(:,1),XY(:,2))
or
tpop=struct2table(pop);
plot(tpop.Cost(:,1),tpop.Cost(:,2))
You've got to get the data into a more amenable form than an array of struct to operate on all at once; this form is good if can apply the same function to each element independently; together, "not so much".
  1 commentaire
Leandro Seguro
Leandro Seguro le 1 Jan 2021
Cheers for that, worked a treat!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by