필터 지우기
필터 지우기

"hold on" on plot does not work over 2 functions

조회 수: 1 (최근 30일)
Hyon Kim
Hyon Kim 2016년 7월 29일
댓글: Hyon Kim 2016년 8월 16일
I have two problem on my code regarding plotting points on a x-y plane.
My code is briefly summarized as follows in main.m and sketch.m;
main.m
plot(x,y,linespec); hold on;
sketch(n);
end
sketch.m
[hx,hy] = ginput(n);
for i = 1:n
plot(hx(i), hy(i), linespec); hold on;
end
What I want to achieve is that:
  1. Create a base x-y plane
  2. Get clicked x-y coordinates on the created x-y plane at the step 1.
  3. Plot all points onto the created x-y plane at the step 1.
And here is my problems;
My first problem is that:
ginput does not follow the x-y coordinate which is created in main file. I think the clicked data is on 1 by 1 x-y plane.
My second problem is that: plot in sketch.m does not work and the program itself freezes and MATLAB also crashes in the end.
If you know how to fix this problem, please let me know and help me out. Thank you so much in advance.

채택된 답변

dbmn
dbmn 2016년 7월 29일
Hi Hyom,
I tried to create a minimal working example from your code but I do not get any errors. Could you describe the errors you get?
Best,
Michael
main.m
function [] = main ()
x = 1:1:10;
y = rand(10,1);
linespec = 'ro-';
plot(x,y,linespec); hold on;
sketch(2);
end
sketch.m
function [] = sketch (n)
[hx,hy] = ginput(n);
for i = 1:n
plot(hx(i), hy(i), 'bo'); hold on;
end
end
  댓글 수: 1
Hyon Kim
Hyon Kim 2016년 8월 16일
Hi Michael
Thanks a lot for your advice. Yes, your code could run. Apparently too big matrix calculation caused the issues. Thanks. Hyon

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

추가 답변 (1개)

Selva Karna
Selva Karna 2016년 7월 29일
you can use
figure

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by