How can I load 100 files with similar names and/or string in just one step in MATLAB?

Related searches

I have 100 ASCII files in my directory all named as follows:

int_001.ASC int_002.ASC int_003.ASC . . . int_099.ASC int_100.ASC

I have to import them in MATLAB all with importdata, which should work as follows:

A = importdata('int_001.ASC', ' ', 9)
x =,1)
y =,2)

My question is: how can I avoid writing 100 times importdata? Is there a way to write the first string only and then have all data uploaded?


fls = dir( 'int_*.ASC' );
for fi=1:numel(fls)
    A{fi} = importdata( fls(fi).name, ' ', 9 );
    % ...

UPDATE: You may use string formatting to read the files according to their numbers:

for fi=1:100
    A{fi} = importdata( sprintf('int_%03d.ASC', fi ), ' ', 9 );
    % ...

How can I import multiple files into the MATLAB workspace , Learn more about import, multiple, files, load, several, read, file, dir, directory, eval If you place all of the files you would like to load into a single directory, you can The EVAL function is used to execute strings containing MATLAB expressions. are .txt files) and save them as arrays with the file name as the array name. Supported File Formats for Import and Export. The following table shows the file formats that you can import and export from the MATLAB ® application.. In addition to the functions in the table, you also can use the Import Tool to import text or spreadsheet file formats interactively.

You can use strcat function in a for loop :

for k=1:n
    fileName = strcat('int_',num2str(k, '%03d'),'.ASC');
    A(k) = importdata(fileName, ' ', 9);
    x(k) = A(k).data(:,1);
    y(k) = A(k).data(:,2);

Load multiple text files one after another, Learn more about multiple text files, common matrix, debug4me. text files and collecting all the outputs into one common matrix) with only little changes to my My steps: download of Data1.01_pre.txt and creation of another five files by The function comprises to parts: creation of a "list" of file names and a loop over all� Import Data from Text Files as Other Data Types. In addition to tables, you can import tabular data from a text file into the MATLAB workspace as a timetable, a numeric matrix, a cell array, or separate column vectors. Based on the data type you need, use one of these functions.

If you want to take this a little overboard:

alldata = arrayfun(...
    @(dirEntry)importdata(, ' ', 9), ...

This line does the following

  1. Gets a listing of all files matching the partial filename, as an array of structures (h/t Shai)
  2. For each element in that array, performs the importdata call from your original post.
  3. Compiles all the outputs into a cell array.

Processing files using a for loop - MATLAB Answers, I want to select data piecewise in a loop, and I want to be able to save the files as filename_number, where the number increases for each iteration of the loop. The idea is: first selection, saved file name is file_1 second selection, saved file Other MathWorks country sites are not optimized for visits from your location. When name is a folder, dir lists the contents of the folder. Specify name using absolute or relative path names. The name argument can include the * wildcard in the file name, and both the * and the ** wildcard in the path name.

Increment file name by adding numbers in a loop, Find and replace text in the current file or multiple files. That is, if two variables use the same name, but are in different scopes, highlighting one does not� My LabVIEW TDMS file has 7 columns of data (N x 7 columns), when I convert them to Matlab, I have 7 data variables representing each column of the original LabVIEW data file, I need these 7 columns to be in a single Matlab.mat file (N x 7 Column) array where each column in Matlab is the same as LabVIEW.

Find and Replace Text in Files - MATLAB & Simulink, readtable('myfile.csv'); this generates a warning -> ' Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.

Type one name, and then each of the files will be saved with the new name and a different sequential number at the end (for example, Renamed File (2), Renamed File (3), and so on). Unfortunately once the file name changed, the original name can’t be reverted automatically. In that scenario you need to manually rename that file.

  • Maybe I've come to the point. By using fls = dir('int_*.ASC') now we have fls(1) = int_091.ASC. I typed fls(1) and what appears is: name = 'int_091.ASC', date = ... and so on. The problem is that if I do importdata('int_091.ASC', ' ', 9) everything is all right; instead, if I do importdata(fls(1), ' ', 9), MATLAB cannot work it out. Should I use a different command?