Load data from mat files to a matrix
이전 댓글 표시
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?
답변 (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
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:
카테고리
도움말 센터 및 File Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!