How do you load xyz files with a similar name but only differ by a number in its name into one manipulatble array?
2 ビュー (過去 30 日間)
古いコメントを表示
I am trying to load .xyz files into Matlab into a single array, so I can write a code that references the different parts of the array. For example, I have 20 different profiles that contain topography data and the coordinates. I want to be able to call any profile at anytime.
The naming system goes like this:
prof1oc.xyz
prof2oc.xyz ...
I want to know how to import them all at the same time. I believe it uses *, but I'm not sure how to write it. Here's an attempt..
%%
numfiles=20;
TopoFiles = dir('*.xyz');
numfiles = length(TopoFiles);
mydata = cell(1, numfiles);
%Creating an array that contains all of the data for each profile
for k = 1:numfiles
profiles{k} = importdata (TopoFiles(k).name);
end
0 件のコメント
回答 (1 件)
Pranjal Priyadarshi
2019 年 2 月 20 日
We can read the list of files using the “dir” command to read the files in the given directory[should be present in the path ] and use “importdata “ command to fetch relevant data from the files list. The following code should do the job for you:
a=dir('p*.txt'); %Used for importing the files list
nooffiles= numel(a);
dataAllFiles={};
for num = 1:nooffiles
dataOfAllFiles(num)=importdata(a(num).name,' '); %importdata used to read the content of the file
end
for n = 1:num
disp(dataOfAllFiles{n}); %printing out the data present in the cell array [Also the data content of the files].
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で HDF5 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!