I have a .mat file that comes out from a pre-designed processing softwarem in MATLAB. This file contains three different arrays (AutoPhased, Complex and Magnitude). For this problem, I only want to focus on the AutoPhased one. I want to now load this data into JavaScript, but I am having trouble doing so.
I have successfully loaded my data in Python using the following code:
data_path = 'path/CSIProcessedData.mat'
data = scipy.io.loadmat(data_path)
data = data['AutoPhased']
data = data[:, :, :, 0, 0, 0, 0] #The data has 4 elements on last dimension but I only want the first
data = np.transpose(data)
This way I obtain a (16,8,1024) array that matches the data I expect. However, I have tried the following in JS using the mat4js:
const buffer = await readFileAsArrayBuffer(file);
matFileData = mat4js.read(buffer);
matFileData = matFileData.data
let processedData = Array(16) // Creates an array with 16 elements
.fill(null).map(() =>
Array(8).fill(null).map(() =>
Array(1024).fill(null)
)
);
for (let i = 0; i < 16; i++) {
for (let j = 0; j < 8; j++) {
for (let k = 0; k < 1024; k++) {
processedData[i][j][k] = data[k][j][i][0][0][0][0].r;
}
}
}
And although I get the (16,8,1024) array, the numbers do not match those on Python. I have observed that the first (0,0,:) to (0,8,:) are correct. However, the rest seem to be a copy of these first 8 arrays, but shifted 8 points. This means that (1,0,0) has the value of (0,0,8); (2,0,0) the value of (0,0,16). I have tried many different ways of parsing the data, but I think the problem is directly on how the mat data is loaded in JS vs in Python.
You can find an example of this data here: https://github.com/marinabatllo-vit/MRSI-data/tree/main
Can anyone help me with this?