Drawing Rectangle/Lines with data

Hello,
I have this matrix,
pic6.JPG
The first column is the base of the rectangle, starting from 0 till 0.15 and the second column is the magnitude of the height at both ends of the rectangle,
I am having trouble drawing it,, here is my code
x1 = 0;
x2 = 0.15;
y1 =[ 0.0120];
y2 = [0.0120];
figure
hold on
plot (x1,y1,'-');
plot(x2, y2,'-');
axis([0 0.5 0 0.1])
But, I am not getting correct results, I am getting nothing in the output.
Does any one know?

 采纳的回答

rectangle('Position',[0 0.15 0.012 0.012])
axis([0 0.02 0 0.2])

6 个评论

Thanks, that was quick :)
Fangjun Jiang
Hey, can you plase tell if I have a file like this :
pic7.JPG
How can I draw a single rectangle with changing height? the second column is the magnitude of the height, the first columns is about lengths of different sections of the rectangle?
Not really follow your question, maybe this?
data=out(1).model_data([1 k],:) % k could be 2, 3 or 4 in this case
rectangle('Position',data(:))
what is k in this case? and it is not working
Fangjun Jiang
I made this code
k = size(out,2);
%% 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
but the result I am getting is some thing like this
pic8.JPG
it is not right, because all the rectangles should be connected I dont know why they are not connected
Just draw it with a pencil manually and match it with the MATLAB code. You've known rectangle(). I don't think there is any difficulty writing code here. It is more difficult to understand what you want to do.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by