I have a txt file, 'matrix.txt', which has 2 matrices of 1400 rows and 1 column each (they are separeted by a space). To save the file into a matrix, I did the following:
matrix = readmatrix('matrix.txt');
which is 1400×2.
But, I have to read each line and each column in a for loop to store the values into another matrix of dimension 4. The loop is described below:
for i = 1:10 for j = 1:10 for k = 1:7 for a = 1:2 big_matrix1(i, j, k, a) = matrix( ?, 1) big_matrix2(i, j, k, a) = matrix( ?, 2) end end endend
Then, my question is where I put the question mark. The loop must work in a sequential way, reading each line of matrix( , 1) at a time. E.g.,
big_matrix1(1,1,1,1) = matrix(1,1)big_matrix1(1,1,1,2) = matrix(2,1)big_matrix1(1,1,2,1) = matrix(3,1)big_matrix1(1,1,2,2) = matrix(4,1)big_matrix1(1,1,3,1) = matrix(5,1)big_matrix1(1,1,3,2) = matrix(6,1)etc...
And that is why my matrix() has 1400 rows, because each row (of each column) is the output of each combination of i, j, k and a (10*10*7*2 = 1400).
So, I don't know how to read each line of matrix( , 1) and matrix( , 2) in a sequential way inside my loop. I cannot add another loop for matrix(n,1), where n=1:1400, because it would get me wrong results.
Also, I tried to use fgetl when reading my matrix.txt, by it stores it as a character vector, and I could not figure out how to read 1 column at a time in fgetl.
Thanks in advance for any help!
Best Answer