Index exceeds matrix dimensions
1 view (last 30 days)
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:
[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); %
importfile ('allgradients.txt'); % here I am importing the file
Gz = data(:,5);
F = length(data(:,5));
for s = 1:F
gradSlsel = Gamma*2*pi*(dT/1000)*Gz(s)*1.7507;
M = zrot(gradSlsel)*M;
time = [0:F]*dT;
axis([min(time) max(time) -1 1]);
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"