Hello, I have such data,
The code which I am using to plot it is this
k = size(out,2); % k =1 since there is only one file in out struct
%% Drawing from the Data Files %
for i =1:1:k
a = size(out(i).model_data,1)
for j =1:1:(a-1)
x1(j) = [out(i).model_data(j,1)];
x2(j) = [out(i).model_data(j+1,1)];
y1(j) = [out(i).model_data(j,2)];
y2(j) = [out(i).model_data(j+1,2)];
rectangle('Position',[x1(j) x2(j) y1(j) y2(j)])
axis([0 0.02 0 0.2])
hold on
end
end
the result, which I am getting is this:
which is not correct, because all the rectangles should join each other, does any one know what to do?

댓글 수: 4

Turlough Hughes
Turlough Hughes 2020년 1월 24일
How exactly do you need the rectangles joining?
Chris Dan
Chris Dan 2020년 1월 24일
편집: Chris Dan 2020년 1월 24일
one after the another, wall to wall, since it is one body with different sections,
just to make one thing clear, the first column is the start and end points of the rectangle and the second column is the height of the rectangle at that point
Is this what you mean?
k = size(out,2);
for i =1:k
a = size(out(i).model_data,1);
for j =1:(a-1)
coord = out(i).model_data(j:j+1,:);
rectangle('Position',[coord(1,1) 0 coord(2,1)-coord(1,1) coord(1,2)])
axis([0 0.2 0 0.02])
hold on
end
end
If so I will move to the answer section.
Chris Dan
Chris Dan 2020년 1월 24일
yeah, thanks :) now it draws correctly
just one question, if the out struct has more than 1 file, then it will also draw correctly?

댓글을 달려면 로그인하십시오.

 채택된 답변

Turlough Hughes
Turlough Hughes 2020년 1월 24일

0 개 추천

You can draw the rectangles from your struct as follows:
k = size(out,2);
figure(), hold on
for i = 1:k
a = size(out(i).model_data,1);
for j =1:(a-1)
coord = out(i).model_data(j:j+1,:);
rectangle('Position',[coord(1,1) 0 coord(2,1)-coord(1,1) coord(1,2)])
axis([0 0.2 0 0.02])
end
end
When you have a non-scalar structure, this plots all rectangles on the same figure. For seperate figures you should move "figure(), hold on" into the first loop.

댓글 수: 3

Chris Dan
Chris Dan 2020년 1월 25일
Thanks, If I were to make this code as a function, the input will be out struct, but what can be the output?
I want as a function, so that I can use it any where as a single line of code
You would have no output, so it would go something like
function [] = myrectangles(out)
% code above
end
Hi, sorry to disturb you again, but I have one small question
the first column is the start and end points of the rectangle and the height of the rectangle is the second column - third column is at that point.
Can you tell me what to change in your code:
k = size(MD,1);
figure(), hold on
for i = 1:k
a = size(MD(i),1);
for j =1:(a-1)
coord = out(i).model_data(j:j+1,:);
rectangle('Position',[coord(1,1) 0 coord(2,1)-coord(1,1) coord(1,2)])
axis([0 0.2 -0.1 0.2])
end
end
Also, can I draw inverted shape below the zero axis?
Thanks for helping me

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 1월 25일

0 개 추천

You could build a polyshape array with one element for each region that you want to draw. Once you've built your polyshape array you can plot it. I'm creating polyshape objects N using the nsidedpoly function, but you could call polyshape with the coordinates of the vertices to build the N's that are combined with union into the polyshape array.
A = polyshape;
for nsides = 3:6
N = nsidedpoly(nsides, 'Center', [nsides nsides], 'Radius', 0.5);
A = union(A, N);
end
plot(A)

카테고리

도움말 센터File Exchange에서 Elementary Polygons에 대해 자세히 알아보기

질문:

2020년 1월 24일

댓글:

2020년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by