From 2D data to a 3D matrix

2 次查看(过去 30 天)
matnewbie
matnewbie 2018-5-24
重新打开: Stephen23 2018-5-25
I have a folder with 2D data stored in 128 files (from number 001 to number 128), whose name has this general form:
7528_00###.txt
where ### represents numbers from 001 to 128. I want to load these data in a 3D matrix in MATLAB, because this is a more manageable data structure. What is the best approach to achieve this task?
  1 个评论
Stephen23
Stephen23 2018-5-24
编辑:Stephen23 2018-5-24
@matnewbie: what file format do the files use? What size are the 2D matrices?

请先登录,再进行评论。

回答(3 个)

Nicola Bombace
Nicola Bombace 2018-5-24
Based on your comment, you could obtain the filename using a for loop and the function sprintf.
nFiles = 128;
for n = 1 : nFiles
filename = sprintf('%s%03d','7528_00',n);
% Process File
end

Aditya Adhikary
Aditya Adhikary 2018-5-24
for i = 1:128
x = sprintf('7528_00%03d.txt',i);
%load your file using x
end

Stephen23
Stephen23 2018-5-24
S = dir('7528_00*.txt');
N = numel(S);
A = nan(128,128,N);
for k = 1:N
S(k).name
A(:,:,k) = ... load your data file
end

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by