0

I want to show image and plot in the loop. I want to show image in one figure and plot in other figure. So I try to use my code, but it does not work. Could you help me fix it? Thanks so much

x=0;
x_arr=[]
I=imread('peppers.png');
figure
for i=1:100
    if mod(i,10)==0
    pause(0.5);
    x=i.^2+1;
    x_arr=[x_arr x]
   %show image
    hold on
    imshow(I);
    hold off
    %show plot
    pause(0.5);
    hold on
    plot(y_arr);
    hold off
    end
end
1

1 Answer 1

2

you can do so by using figure for handeling 2 windows:

x=0;
x_arr=[]
I=imread('peppers.png');

for i=1:100
    if mod(i,10)==0
    pause(0.5);
    x=i.^2+1;
    x_arr=[x_arr x];
   %show image

   figure(1)
    imshow(I);

    %show plot
    pause(0.5);
    figure(2)
    plot(x_arr);
    end
end

or by using subplots to keep it in one window:

x=0; x_arr=[] 
I=imread('peppers.png'); 
figure (1) 
for i=1:100
    if mod(i,10)==0
    pause(0.5);
    x=i.^2+1;
    x_arr=[x_arr x]    %show image
    subplot(1,2,1);
    imshow(I);

    %show plot
    pause(0.5);
    subplot(1,2,2)
    plot(x_arr);
    end 
 end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.