필터 지우기
필터 지우기

I'm trying to plot inside a while loop.

조회 수: 26 (최근 30일)
Evan
Evan 2022년 12월 11일
답변: Rohit 2022년 12월 19일
Hello, I'm working on a project, and I'm trying to plot two arrays on one graph inside a while loop. The reason I'm plotting inside the while loop is because I have to make sure my code can run again if the user would like to run it again. I want the plot to be pop up and then the code asks for the user's input. What's been happening is the code skips over the plot and asks for the users input. The code only plots when the user ends says no to running it again and then it plots. If this is impossible plese let me know.
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 12월 12일
Please post the relevant section of code.
Evan
Evan 2022년 12월 12일
Nevermind, I was allowed to change the parameters. I also learned about the drawnow function.

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

답변 (1개)

Rohit
Rohit 2022년 12월 19일
Hello,
I am adding a sample example below which plots 2 arrays ‘a’,’b’ (wrt ‘t’) inside a while loop based on user’s input ‘x’. You can take it as a reference and based on your use case modify the below code.
x=1;
t=[1,2,3];
a=[2 1 1];% First array
b=[4,5,3];% Secind array
cnt=1;% Plot count
while(x==1)
fig=figure(1);
plot(t,b);
hold on;
plot(t,a);
hold off;
fig.Name=['Plot ' num2str(cnt)];
drawnow
x=input('Press 1 if you want to plot again\n');
b=b+1;
cnt=cnt+1;
end
You can refer to the following documentation link for drawnow function along with a related MATLAB Answers link:

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by