简体   繁体   中英

How to plot data dynamically in MATLAB

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM