MATLAB: How do i use for to populate matrix

for loop matrix population

iv'e run this code bust i get the error message below. Index exceeds matrix dimensions.
Error in Import_dat_files (line 20) x(j,:) = A((j-1)*nx+1:j*nx,1);
Can anyone help please this is the code below
filename= 'B00049.dat';
delimiterIn= ' ';
headerlinesIn = 3;
A = importdata(filename,delimiterIn,headerlinesIn);
%% Matrices%%%%
xi = 214; yj = 134;
x= zeros(yj,xi);
y= zeros(yj,xi);
u= zeros(yj,xi);
v= zeros(yj,xi);
%% Matrix population
for j=1:xi x(j,:) = A((j-1)*xi+1:j*xi,1);
y(j,:) = A((j-1)*xi+1:j*xi,2);
u(j,:) = A((j-1)*xi+1:j*xi,3);
v(j,:) = A((j-1)*xi+1:j*xi,4);
end

Best Answer

The text of the error does not match the code you're showing. Your code has the line
x(j,:) = A((j-1)*xi+1:j*xi,1);
The error says the line is
x(j,:) = A((j-1)*nx+1:j*nx,1);
One has nx, the other xi.
In any case, if you get the error, it's because A does not have xi^2 or nx^2 rows. What is
size(A)
Related Question