How to plot a struct with 2 fields in Matlab

3 vues (au cours des 30 derniers jours)
Hamed Bolandi
Hamed Bolandi le 17 Juil 2019
Modifié(e) : Hamed Bolandi le 18 Juil 2019
I have T=81x4 struct, each member has two fields (x and y cordinate). I want to plot each row which will be 4 nodes to make a rectangular by connecting the nodes. Totally it should be 81 rectangular. I am wondering how can I plot each row of struct with 2 fields. I would appreciate if anyone can help me.
for i=1:81
plot(T(i,:).x,T(i,:).y,'.')
xlim([-50 50]);
ylim([-50 50]);
k = boundary(x,y);
hold on;
plot(x(k),y(k));
end

Réponse acceptée

Bruno Luong
Bruno Luong le 17 Juil 2019
Try this
x=reshape([T(:).x],size(T));
y=reshape([T(:).y],size(T));
plot(x(:,[1:end 1])',y(:,[1:end 1])')
  1 commentaire
Hamed Bolandi
Hamed Bolandi le 17 Juil 2019
Modifié(e) : Hamed Bolandi le 18 Juil 2019
Thank you so much Bruno. It worked.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Objects 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