# Index exceeds matrix dimensions

1 view (last 30 days)
Azza Ahmed on 5 Jan 2012
Hello,
I think I have a problem with my matrices but I can't figure out where to fix it. I am trying to read a text file of size 28179*6. The code that I have written is:
clear all
[A,B] = freeprecess(dT,T1,T2,df);
M = zeros(3,N);
M(:,1) = [0;0;1];
M(:,2)= throt(abs(Rflip(1)),angle(Rflip(1))) * M(:,1); %
M(:,3)=A*M(:,2)+B;
importfile ('allgradients.txt'); % here I am importing the file
Gz = data(:,5);
F = length(data(:,5));
for s = 1:F
M(:,s)=A*M(:,s)+B;
time = [0:F]*dT;
plot(time,M(1,:),'b-',time,M(2,:),'r--',time,M(3,:),'g-.');
legend('M_x','M_y','M_z');
xlabel('Time (ms)');
ylabel('Magnetization');
axis([min(time) max(time) -1 1]);
grid on;
end;
The message that I get is "Index exceeds matrix dimension". As I can see dim of Gz is the same as time. So where would be the problem and how can I fix it?
Would you kindly help me with this?

Walter Roberson on 5 Jan 2012
Your time vector is one longer than Gz is.
Your code assumes that M is the same length as time, but M could be larger since M is initialized as 3 by N and we do not know the relationship between N and F.
Note that if N is smaller than F, then M grows inside the loop and so will not be the same size as the fixed-length "time"