Azzera filtri
Azzera filtri

Several rectangles, fast way?

1 visualizzazione (ultimi 30 giorni)
Daniel
Daniel il 7 Ago 2011
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 :)

Risposte (2)

Walter Roberson
Walter Roberson il 7 Ago 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 Commento
Walter Roberson
Walter Roberson il 10 Ago 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]) )

Accedi per commentare.


Daniel
Daniel il 10 Ago 2011
Hi Walter,
thanks for your answer :)
This a plot for a FDTD programm where I simulate wave propagation through a liquid. When I said 5 mm I meant the x-y axis: element*dx. It is only for visualization, not for grid calculus.

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by