是否有解决方案来打印和绘制Matlab中数组或随机输入的测试代码结果?

问题描述 投票:1回答:1

我是Matlab领域的新手。

情况是,当我仅输入一个输入变量时,程序运行没有错误。但是,当我使用random或array时,程序只在Per数组的所有值大于或小于D时才起作用,除了我的程序不在Command窗口中显示结果。

无论大于或小于D,我都会掌握当前情况的所有信息。我还想知道如何随时间(小时)的函数在同一张图中打印结果Per,D,S和Psc,无论随机数/数组变量的最大值或大小如何。

感谢您的帮助。

clear all
clc
%t=1:24;
Ppv=2*rand(1,5); %[10 0 40 50 5 1 2 3 1 1 1 1];  
Pwt=rand(1,5); %[10 0 40 5 5 1 2 3 3 4 55 5];  

LPac=rand(1,5); %[10 20 40 50 5 1 2 3 5 6 7 9]; 
LSac=rand(1,5); %[1 2 40 5 51 2 3 33 9 0 3 2];

LPdc=rand(1,5); %[1 20 4 50 51 24 3 3 4 6 7 8];
LSdc=rand(1,5); %[10 0 4 0 51 2 324 3 8 5 3 2];


 for i=1:1:1
    Dac=LPac+LSac; 
   Ddc=LPdc+LSdc; 
   Per=Ppv+Pwt; 
    D=Dac+Ddc;   
   Lp=LPac+LPdc; 
    Ls=LSac+LSdc; 

        if Per>D 
   if   Sac)>0  && Sdc>0 
        fprintf(' S de %d .\n',S)
       fprintf(' Sac de %d .\n',Sac) 
       fprintf(' Sdc de %d .\n',Sdc)
       fprintf(' St de %d .\n',St)
   end

if  Ppv>Ddc &  Pwt<=Dac
   SDC=Sdc-abs(Sac);
   SAC=0;
   fprintf(' S de %d .\n',S)
  fprintf(' DC Sdc de %d .\n',SDC)
  printf('  St de %d .\n',St)
       elseif   any(Sac )>0 & any(Sdc)<=0
  SAC=Sac-abs(Sdc);
  SDC=0;
  fprintf(' S de %d .\n',S)
  fprintf(' Sac de %d .\n',SAC)
  fprintf('  St de %d .\n',St)
end

if Per < D

Lp=LPac+LPdc; 
Ls=LSac+LSdc; 
DDdc=Ppv-LPdc;
Ddeldc=LSdc-abs(DDdc); 
DDac=Pwt-LPac;
Ddelac=LSac-abs(DDac); 
DD=DDac+DDdc; 
Ddel=Ddeldc+Ddelac ; 

  if Per>=Lp
          fprintf(' Ddel de %d .\n',Ddel)
              if Ppv>=LPdc || Pwt>=LPac

          fprintf(' Ddeldc de %d .\n',Ddeldc)
          fprintf('Ddelac de %d .\n',Ddelac)
              end

  else
              Dextdc=Ppv-LPdc; 
              Dextac=Pwt-LPac;   
              Dext=Dextdc+Dextac; 
              Psc=abs(Dext); 

                    if Ppv<LPdc && Pwt>LPac
               Pscac=0;
               Pscdc=abs(Dextdc+Dextac);
                elseif Ppv>LPdc && Pwt<LPac
               Pscac=abs(Dextac+Dextdc);
               Pscdc=0;
                    else Ppv<LPdc && Pwt<LPac

              Pscac=abs(Dextac);
              Pscdc=abs(Dextdc);
                    end  
            fprintf('Ddel %d .\n',Ls) 
            fprintf('Pscdc %d .\n',Pscdc)
            fprintf('Pscac %d .\n',Pscac) 
            fprintf('Psc %d . \n',Psc)

    end 
    end

      if Per==D
           disp(" tout est bien ")
      end

      end
matlab matlab-figure
1个回答
0
投票

我在理解问题的第一部分时遇到了一些麻烦,但是在同一幅图上绘制几个变量很容易:

figure; hold on
plot(Per); plot(D); plot(S); plot(Psc);
hold off
© www.soinside.com 2019 - 2024. All rights reserved.