Info

This question is closed. Reopen it to edit or answer.

have a problem when I execute my code. It keeps giving me the message (Index exceeds matrix dimensions.) I am including my code for reference. Any help would be appreciated. Thanks a lot

1 view (last 30 days)
%x = zeros(n, 1);
%for i = 1:n
%x(i) = i * sin( i^2 *pi/n );
%end
% v is the vector of voltage
% C is the current I
% CS is the current Is
T=3000;
vth=((1.3806503*10^-23)*300)/(1.602176527*10^-19);
%T = 3000; %%number of iterations
%t=1:T;
%e1 = 2*(rand(size(t))-0.5); %% U(-1,1)
CS=1.919*10^-20;
rs=3.38;
rsh=3.105^10^9;
%C=zeros (51);
mu=1.0179;
for v=[1:0.85, 0.849, 0.849, 0.848, 0.848, 0.848, 0.82, 0.79, 0.76, 0.73, 0.7, 0.67, 0.64, 0.61, 0.58, 0.55, 0.52, 0.49, 0.46, 0.43, 0.4, 0.37, 0.34, 0.31, 0.28, 0.25, 0.22, 0.19, 0.16, 0.13, 0.1, 0.0701, 0.04, 0.01, -0.0199, -0.0499, -0.08, -0.11, -0.14, -0.17, -0.2, -0.23, -0.26, -0.29, -0.32, -0.35, -0.38, -0.41, -0.44, -0.47, -0.5]
C=CS.*(exp((v-rs*C)/(mu*vth))-1) + (v-rs*C)/rsh;
end
%i
subplot(2,2,2);
plot(C(1,1:T-1));
xlabel('Voltage' );
ylabel(' Current');
title('Experimental data (dots) and numerical characteristic (line) ');
  4 Comments

Answers (1)

Walter Roberson
Walter Roberson on 19 Oct 2011
The code you show cannot run. You do not initialize C anywhere, so it is not available to be used on the right hand of the assignment in the "for v" loop, so the code would crash.
If you were to remove the comment character and thus expose
C=zeros(51);
then that would initialize C to be a 51 x 51 array. Then after the "for v" loop, you attempt to access
C(1,1:T-1)
where T is 3000. There would, however, not be any element C(1,52) through C(1,2999) so the code would crash with a complaint about index exceeding matrix dimension.
Note: a 51x51 array only has 2601 total elements in it, so looking for the 2999th element if it is not going to work.
  2 Comments
Gihan
Gihan on 20 Oct 2011
Thanks Walter for you suggestions. However I tried them with no hope ! I need this file to work soon , so any help will be appreciated.
Naz
Naz on 20 Oct 2011
It would be better for you to post the actual problem that you are trying to solve. It's just difficult to understand what your script should do. Also, there could be a better approach to implement the code.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!