title: index exceed matrix dimensions
body: <p>i have the same problem as this discussion before, </p>
  
  <p>[here] <a href="https://stackoverflow.com/questions/14515051/can-someone-explain-how-to-graph-this-sum-in-matlab-using-contourf">Can someone explain how to graph this sum in MATLAB using contourf?</a></p>
  
  <p>however, for now i haven't deal with the contourf, because i have two other question that i have to answer.</p>
  
  <p>I'm told to take N = 50, phi1 = 300, phi2 = 400, 0&lt;=x&lt;=1, and 0&lt;=y&lt;=1, and to let x and y be vectors of 100 equally spaced points, including the end points.</p>
  
  <p>and heres the two question,</p>
  
  <p>a) In a single figure (Figure 1), plot phi(x,y=1), phi(x,y=0.8), phi(x,y=0.5), and phi(x,y=0.1). Make sure the axes are labeled, and the curves are in distinct colors.</p>
  
  <p>b) In a separate figure (Figure 2), plot phi(x,y=1), phi(x,y=0), phi(x=0,y), and phi(x=1,y) as subplots (i.e. 4 separate sub-figures). Make sure everything is labeled, and the greek letter phi appears as is in the yaxis label.</p>
  
  <p>I have already answer for question a), however when i try to answer question b, i got the error. help?</p>
  
  <pre><code>clear all
  close all
  clc
  clear
  
  N=50;
  phi1=300;
  phi2=400;
  %Phix10
  %Phix08
  %Phix05
  %Phix01
  x=linspace(0,1,100);
  y=linspace(0,1,100);
  
  y=1;
  for k=1:100
     sum=0;
     tot=0;
      for n=1:N
          sum= sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
      end
      Phi10(k)=phi1 - sum;
  end
  
  y=.8;
  for k=1:100
     sum=0;
     tot=0;
      for n=1:N
          sum= sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));   
      end
      Phi08(k)=phi1 - sum;
  end
  
  y=.5;
  for k=1:100
     sum=0;
     tot=0;
      for n=1:N
          sum=sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
      end
      Phi05(k)=phi1 - sum;
  end
  
  y=.1;
  for k=1:100
     sum=0;
     tot=0;
      for n=1:N
          sum=sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
      end
      Phi01(k)=phi1 - sum;
  end
  
  
  figure(1);
  plot(x,Phi10,'r');
  hold on;
  plot(x,Phi08,'g');
  hold on;
  plot(x,Phi05,'y');
  hold on;
  plot(x,Phi01);
  hold on;
  title('plotting 1');
  xlabel('x');
  ylabel('y');
  
  
  %my answer for question b
  y=1;
  for k=1:100
     sum=0;
     tot=0;
      for n=1:N
          sum= sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
      end
      PhiB1(k)=phi1 - sum;
  end
  
  y=0;
  for k=1:100
     sum=0;
     tot=0;
      for n=1:N
          sum = sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
      end
      PhiB2(k)=phi1 - sum;
  end
  
  x=0;
  for k=1:100
      sum=0;
      for n=1:N
  
            % here's where i got the error
            sum = sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y(k))+(exp(n*pi)-1)*exp(-n*pi*y(k)))*sin(n*pi*x);
      end
      PhiB3(k)=phi1 - sum;
  end
  
  % x=1;
  % for k=1:100
  %     sum=0;
  %     for n=1:N
  %         sum= sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x);
  %     end
  %     PhiB4(k)=phi1 - sum;
  % end
  
  figure(2);
  plot(x,PhiB1,'r');
  hold on;
  plot(x,PhiB2,'g');
  hold on;
  plot(x,PhiB3,'y');
  hold on;
  plot(x,PhiB4);
  hold on;
  </code></pre>