Load data from mat files to a matrix
46 views (last 30 days)
Show older comments
Hello! I have 50 .mat files and each of them has 4 structures inside. I want to take from .mat file the structure named ' Data'.
In this 'Data' structure, there are 4 columns. i need the last column from each data file, from each .mat file and load it in an empty matrix
for ex: 1.mat ->Numbers, Files, Names and Data -> Data = [1 2 3
4 5 6
7 8 9] -> i need the column 3 6 9 to load into a matrix in matlab as a row of it. And fill the matrix with the last columns of each data file.
Matrix=[Data1.1 Data1.2 Data1.3 ; Data2.1 Data2.2 Data2.3 ; .... ; Data50.1 Data50.2 Data50.3]
Do you know if i can do that?
0 Comments
Answers (2)
JESUS DAVID ARIZA ROYETH
on 20 Nov 2019
if your data is called 1.mat, 2.mat, 3.mat and so on, and in addition each of these data contains a structure called "Data" and in this same structure there is a field called "Data" and in this field There is a matrix of which you want the last column, so the solution is as follows:
matrix=[];
for k=1:50
dd=load(num2str(k,'%i.mat'));
matrix=[matrix dd.Data.Data(:,end)];
end
disp(matrix)
Espero te sea de ayuda y sea la solución de tu requerimiento
0 Comments
Stephen23
on 20 Nov 2019
N = 50;
C = cell(1,N);
for k = 1:N
F = sprintf('%d.mat',k);
S = load(F);
C{k} = S.Data(:,3);
end
M = [C{:}]
See also:
0 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!