Menu

Strange phenomenon with large size matrix

Help
2007-05-26
2013-04-25
  • Nobody/Anonymous

    I am testing octplot to print 30 PNG pictures with 4 subplots using looping. And, I choose small spacing for matrix x and y to create a 101x101 matrix 
    So, It will be a heavy task for slow computer.

    Try the following 2 codes listed below:
    "massive_print.m" and "massive_print2.m"

    The difference is the first one use the set command to set the 'XTick' and 'XTickLabel' which is not used in the second one.

    However, the second one, "massive_print2.m", usually has runtime error while the first one, "massive_print.m", is less likely to have runtime error.
    Why does it so strange?

    Note:  when you use a small matrix size for x, y and z, there will be  no error for both cases.

    -----------------------------------------------------------------

    1. Save the code below into "massive_print.m"

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % if use the "set" command      %
    % No runtime error with text    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Please run this script under a sub-directory
    % it will save the picture "1.png" to "30.png"
    % For exmaple, create a sub-directory "test-massive"
    % mkdir test_massive; cd test_massive;

    octplot_enable;
    for index=1:30
      x=[0:0.05:5];
      y=[(index-1):0.05:(index+4)];
      z=zeros(101);
      for i=1:101
       for j=1:101
        z(i,j)=x(i)+y(j)+sin(y(j));
       end
      end

      subplot(2,2,1);
      colormap('rainbow');
      contour(x,y,z,linspace(0,30,50));
      axis([0 5 index-1 index+4]);
      axis('equal');
      title(num2str(index));
      text(3.5,index+4.3,strcat("num=",num2str(index,"%6.2f")));
      set(gca(),'XTick',[0 1 2 3 4 5]);
      set(gca(),'XTickLabel','0|1|2|3|4|5');

      subplot(2,2,2);
      colormap('rainbow');
      contour(x,y,z,linspace(0,35,80));
      axis([0 5 index-1 index+4]);
      axis('equal');
      title(num2str(index));
      text(3.5,index+4.3,strcat("num=",num2str(index,"%6.2f")));
      set(gca(),'XTick',[0 1 2 3 4 5]);
      set(gca(),'XTickLabel','0|1|2|3|4|5');

      subplot(2,2,3);
      colormap('rainbow');
      contour(x,y,z,linspace(0,40,90));
      axis([0 5 index-1 index+4]);
      axis('equal');
      title(num2str(index));
      text(3.5,index+4.3,strcat("num=",num2str(index,"%6.2f")));
      set(gca(),'XTick',[0 1 2 3 4 5]);
      set(gca(),'XTickLabel','0|1|2|3|4|5');

      subplot(2,2,4);
      colormap('rainbow');
      contour(x,y,z,linspace(0,50,100));
      axis([0 5 index-1 index+4]);
      axis('equal');
      title(num2str(index));
      text(3.5,index+4.3,strcat("num=",num2str(index,"%6.2f")));
      set(gca(),'XTick',[0 1 2 3 4 5]);
      set(gca(),'XTickLabel','0|1|2|3|4|5');

      prtcmdstr=strcat("print -r100 -dpng ",num2str(index),".png;");
      eval(prtcmdstr);
      pause(4);
    end
    ----------------------------------------------------------------

    2. Save the code below into "massive_print2.m"

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % if do not use the "set" command %
    % with runtime error with text    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Please run this script under a sub-directory
    % it will save the picture "1.png" to "30.png"
    % For exmaple, create a sub-directory "test-massive"
    % mkdir test_massive; cd test_massive;

    octplot_enable;
    for index=1:30
      x=[0:0.05:5];
      y=[(index-1):0.05:(index+4)];
      z=zeros(101);
      for i=1:101
       for j=1:101
        z(i,j)=x(i)+y(j)+sin(y(j));
       end
      end

      subplot(2,2,1);
      colormap('rainbow');
      contour(x,y,z,linspace(0,30,50));
      axis([0 5 index-1 index+4]);
      axis('equal');
      title(num2str(index));
      text(3.5,index+4.3,strcat("num=",num2str(index,"%6.2f")));
      %set(gca(),'XTick',[0 1 2 3 4 5]);
      %set(gca(),'XTickLabel','0|1|2|3|4|5');

      subplot(2,2,2);
      colormap('rainbow');
      contour(x,y,z,linspace(0,35,80));
      axis([0 5 index-1 index+4]);
      axis('equal');
      title(num2str(index));
      text(3.5,index+4.3,strcat("num=",num2str(index,"%6.2f")));
      %set(gca(),'XTick',[0 1 2 3 4 5]);
      %set(gca(),'XTickLabel','0|1|2|3|4|5');

      subplot(2,2,3);
      colormap('rainbow');
      contour(x,y,z,linspace(0,40,90));
      axis([0 5 index-1 index+4]);
      axis('equal');
      title(num2str(index));
      text(3.5,index+4.3,strcat("num=",num2str(index,"%6.2f")));
      %set(gca(),'XTick',[0 1 2 3 4 5]);
      %set(gca(),'XTickLabel','0|1|2|3|4|5');

      subplot(2,2,4);
      colormap('rainbow');
      contour(x,y,z,linspace(0,50,100));
      axis([0 5 index-1 index+4]);
      axis('equal');
      title(num2str(index));
      text(3.5,index+4.3,strcat("num=",num2str(index,"%6.2f")));
      %set(gca(),'XTick',[0 1 2 3 4 5]);
      %set(gca(),'XTickLabel','0|1|2|3|4|5');

      prtcmdstr=strcat("print -r100 -dpng ",num2str(index),".png;");
      eval(prtcmdstr);
      pause(4);
    end
    ----------------------------------------------------------------

     
    • Shai Ayal

      Shai Ayal - 2007-05-26

      I ran both the m-files on current svn (which is basically octplot 0.4.0) and octave 2.9.10+ without any runtime error.
      Can you give us some more info? octplot version, octave version, OS? This is not a problem with slow cpu or little memory -- my dev laptop is 800Mhz P3 with 256 MB Ram -- you probably can't get much slower than that ...

      Shai

      p.s. I took the liberty to change the for-loop you use to populate z with the following one-liner (which is of course much faster):

      z = x'*ones(1,101) + ones(101,1)*(y + sin(y));

       
    • Nobody/Anonymous

      This problem only happens when I try it with the unstable "native MSVC compiled" version of Octave 2.9.9 with Octplot 0.3.9+. But it is strange to me that why there is such a difference with minor change in the script.

      Again, No error for both cases when I use Octplot 0.4.0 with Octave 2.1.73 in Cygwin.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.