Several rectangles, fast way?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to plot several rectangles (for an ultrasonic transducer simulation).
I tried to plot them with only one instruction but it doesn't works.
elementX = Matrix with Nx2 elements (normally N = 32). First column element start and second column element stop. Horizontal position.
elementY = Matrix (array) Nx1 elements. Vertical position of each element.
elementSize = Widh of each element.
0.005 = 5 milimeters of element high.
So, I tried it with repmat to create several arrays as a 'elegant' solution for avoiding a for loop. But it doesn't works :( Any help?
My NOT workin code:
rectangle('Position',[elementX(:,1)*dh,elementY*dh,repmat(elementSize,N,1),repmat(0.005,N,1)],'FaceColor','y')
Thanks for your help :)
0 commentaires
Réponses (2)
Walter Roberson
le 7 Août 2011
rectangle() will only plot a single rectangle per call.
plot() will produce one lineseries per column of input.
For example, the x coordinates can be constructed similar to
elementx(:,[1 2 2 1 1]).'
I do not understand about "5 millimeters of element high" ? Note for one thing that plotting units are normally data coordinates rather than millimeters.
1 commentaire
Walter Roberson
le 10 Août 2011
Is elementSize perhaps the *height* of each element? So element K has Y coordinates elementY(K) to elementY(K)+elementSize(K) ? If not then I do not know how to deduce the height of the rectangle.
T = [elementY, elementY+elementSize];
plot( elementx(:,[1 2 2 1 1]), T(:,[1 1 2 2 1]) )
Voir également
Catégories
En savoir plus sur Labels and Styling 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!