0

I am having trouble plot the data dynamically,my goal is to plot data after checking a certain test of 14 days if I entered that condition loop I would like to execute a rectangle between the 1st day and the 14th day. when I enter that last if loop I already have a xfist,xlast,y first y last. so I can draw a rectangle between them. And then when I pass the 14 days test again I would like to add to the existing plot another rectangle.

Here is my code so far.

The plot lines don't plot anything.

j=1;    
      while(j<72)
         boom=true;             
           if a13(j)~= b8(j)|| a13(j)>1.1*(b8(j))&& a13(j)<0.9*(b8(j))
           elseif a13(j)~=c5(j)|| a13(j)<0.9*(c5(j))&&a13(j)<0.9*(c5(j))
               boom=false;

           end
        Xfirst=[];
            Yfirst=[];
            Xlast=[];
            Ylast=[];
            Yfirst=a13(j);
            Xfirst=datetime(Date(j));           
          for i=j+1 :j+14 
            if a13(i)~= b8(i)|| a13(i)>1.1*(b8(i))&& a13(i)<0.9*(b8(i))
            elseif a13(i)~= c5(i) || a13(i)<0.9*(c5(i)) && a13(i)>1.1*(c5(j)) 
                 j=i;
                boom=false;
                break;
            end
          end
           if(boom==true)
                Ylast=a13(j+14);
                Xlast=New_Date(j+14);
                figure (1)
                plot(Xfirst,Yfirst)
                hold on
               plot(Xlast,Ylast)
           end 
           j=j+1;
      end
4
  • Where are you stuck with this code? What have you tried extending this code to what you actually require? Also please see: Why is “Can someone help me?” not an actual question?, or in your case "Please advice", which isn't even a question. Commented Sep 24, 2018 at 20:59
  • It doesn't plot anything. Commented Sep 24, 2018 at 21:02
  • Which still is not a question, merely a statement as to the current state of the code. Commented Sep 24, 2018 at 21:03
  • The question is what I need to add\change in order to plot those rectangles between my coordiantes Commented Sep 24, 2018 at 21:08

1 Answer 1

2

use drawnow inside the loop:

j=1;


  while(j<72)
     boom=true;             
       if a13(j)~= b8(j)|| a13(j)>1.1*(b8(j))&& a13(j)<0.9*(b8(j))
       elseif a13(j)~=c5(j)|| a13(j)<0.9*(c5(j))&&a13(j)<0.9*(c5(j))
           boom=false;

       end
    Xfirst=[];
        Yfirst=[];
        Xlast=[];
        Ylast=[];
        Yfirst=a13(j);
        Xfirst=datetime(Date(j));           
      for i=j+1 :j+14 
        if a13(i)~= b8(i)|| a13(i)>1.1*(b8(i))&& a13(i)<0.9*(b8(i))
        elseif a13(i)~= c5(i) || a13(i)<0.9*(c5(i)) && a13(i)>1.1*(c5(j)) 
             j=i;
            boom=false;
            break;
        end
      end
       if(boom==true)
            Ylast=a13(j+14);
            Xlast=New_Date(j+14);
            figure (1)
            plot(Xfirst,Yfirst)
            hold on
           plot(Xlast,Ylast)
           drawnow; % To force figure to update
           pause(0.2); % to allow time for it to render
          end 
       j=j+1;
  end

drawnow updates figures and processes any pending callbacks. Use this command if you modify graphics objects and want to see the updates on the screen immediately.

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.