필터 지우기
필터 지우기

Several rectangles, fast way?

조회 수: 1 (최근 30일)
Daniel
Daniel 2011년 8월 7일
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일
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일
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.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by