Several rectangles, fast way?

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 :)

回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 8 月 7 日

1 投票

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 件のコメント

Walter Roberson
Walter Roberson 2011 年 8 月 10 日
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]) )

サインインしてコメントする。

Daniel
Daniel 2011 年 8 月 10 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeLabels and Styling についてさらに検索

タグ

質問済み:

2011 年 8 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by