How do you load xyz files with a similar name but only differ by a number in its name into one manipulatble array?
조회 수: 6 (최근 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에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!