필터 지우기
필터 지우기

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