How to read multiple files in a loop in sequential order and plot them as matrix

 Accepted Answer

txtFiles = dir('*.txt') ;
N = length(txtFiles) ;
iwant = cell(1,N) ;
for i = 1:N
iwant{i} = importdata(txtFiles(i).name) ;
end
% works if all cells are of same size
M = cell2mat(iwant) ;
pcolor(M) ;
shading interp

2 Comments

Thanks for your help. I tried this code. My original file has 1444 subfiles and still I am not able to read it in sequential order. My file name is 1_1_1.txt, 1_1_2.txt .........38_1_38.txt . The code is reading the files only from the series 10_1_1.txt
It has to read all the files. What is the value of N and number of files in the folder..are not they same?
You can have a look on the following fileexchange.

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!