Load data from mat files to a matrix
99 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
JESUS DAVID ARIZA ROYETH
2019-11-20
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 个评论
Stephen23
2019-11-20
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!