Index exceeds matrix dimensions

1 次查看(过去 30 天)
Azza Ahmed
Azza Ahmed 2012-1-5
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;
gradSlsel = Gamma*2*pi*(dT/1000)*Gz(s)*1.7507;
M = zrot(gradSlsel)*M;
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?

回答(1 个)

Walter Roberson
Walter Roberson 2012-1-5
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"

类别

Help CenterFile Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by