在matlab中使用while循环

时间:2014-04-14 13:02:52

标签: matlab loops subplot

让我们考虑以下代码

clear all;
 B=xlsread('data_generations1','A1','g8:g301');
% n=input('enter the number  from 1 to 16 for  windows  in periodogram :');
 fs=input('enter sampling frequency  fs :');
 while  1
     n=input('enter the number  from 1 to 16 for  windows  in periodogram :');
 switch n
     case 1
         disp('this is  hann window ');
         [pxx,f]=periodogram(B,hann(length(B)),length(B),fs);
         subplot(4,4,1);
         plot(f,pxx);
         hold on
     case 2
         disp('this is hamming window ');
         [pxx,f]=periodogram(B,hamming(length(B)),length(B),fs);
         subplot(4,4,2);
         plot(f,pxx);
         hold on
     case 3
         disp('this is kaiser window ');
         [pxx,f]=periodogram(B,kaiser(length(B),2.5),length(B),fs);
        subplot(4,4,3);
         plot(f,pxx);
         hold on
     case 4
         disp('this is barlett window ');
         [pxx,f]=periodogram(B,bartlett(length(B)),length(B),fs);
         subplot(4,4,4);
         plot(f,pxx);
         hold on
     case 5
         disp('this is bohmanwin window ');
         [pxx,f]=periodogram(B,bohmanwin(length(B)),length(B),fs);
         subplot(4,4,5);
         plot(f,pxx);
         hold on
     case 6
          [pxx,f]=periodogram(B,rectwin(length(B)),length(B),fs);
         subplot(4,4,6);
         plot(f,pxx);
         hold on

     case 7
          [pxx,f]=periodogram(B,triang(length(B)),length(B),fs);
         subplot(4,4,7);
         plot(f,pxx);
         hold on

     case 8
          [pxx,f]=periodogram(B,gausswin(length(B),2.5),length(B),fs);
         subplot(4,4,8);
         plot(f,pxx);
         hold on

     case 9
          [pxx,f]=periodogram(B,flattopwin(length(B),'periodic'),length(B),fs);
         subplot(4,4,9);
         plot(f,pxx);
         hold on

     case 10
          [pxx,f]=periodogram(B,gausswin(length(B),2.5),length(B),fs);
         subplot(4,4,10);
         plot(f,pxx);
         hold on

     case 11
         [pxx,f]=periodogram(B,tukeywin(length(B),0.5),length(B),fs);
         subplot(4,4,11);
         plot(f,pxx);
         hold on
     case 12 
         [pxx,f]=periodogram(B,taylorwin(length(B)),length(B),fs);
         subplot(4,4,12);
         plot(f,pxx);
         hold on
     case 13
        [pxx,f]=periodogram(B,barthannwin(length(B)),length(B),fs);
         subplot(4,4,13);
         plot(f,pxx);
         hold on
          case 14 
          [pxx,f]=periodogram(B,parzenwin(length(B)),length(B),fs);
         subplot(4,4,14);
         plot(f,pxx);
         hold on
     case 15
         [pxx,f]=periodogram(B,nuttalwin(length(B),'periodic'),length(B),fs);
         subplot(4,4,15);
         plot(f,pxx);
         hold on

     case 16 
         [pxx,f]=periodogram(B,nuttalwin(length(B),'periodic'),length(B),fs);
         subplot(4,4,15);
         plot(f,pxx);
         hold on
         otherwise
        warning('Unexpected number typed. No windows is used ');
 end
                 break;
 end

我的目标是使用循环我想在每一步输入一些从1到16的数字,并使用具有几个不同窗口的周期图制作功率谱密度的子图,但是当我运行时,它只显示我只绘制一次,这意味着,例如,如果我输入数字1,它显示我的窗口,然后停止,我如何循环完成每个步骤,同时保持以前绘制的图形?提前感谢

1 个答案:

答案 0 :(得分:1)

删除break电话。 break的重点是提前退出循环。由于您不想提前退出,请不要致电break