Several rectangles, fast way?
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Walter Roberson
am 7 Aug. 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 Kommentar
Walter Roberson
am 10 Aug. 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]) )
Siehe auch
Kategorien
Mehr zu Labels and Styling finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!