Azzera filtri
Azzera filtri

How do you load xyz files with a similar name but only differ by a number in its name into one manipulatble array?

6 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Pranjal Priyadarshi
Pranjal Priyadarshi il 20 Feb 2019
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

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by