how to concatenate multiple columns in one column of cell array?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ebtesam Farid
am 10 Jun. 2021
Kommentiert: Ebtesam Farid
am 10 Jun. 2021
Hi guys,
I have text files that have numeric data only, I wrote a loop that read all the text file in my folder and get the data and put them in one column ... but my problem is this code escape some files and hence don't give me the correct numbers of the rows
here is my code, could you tell me, where is the wrong in it?
files = dir('*.txt') ; % you are in the folder of files
N = length(files) ;
T = [];
for i = 1:N
try
filename = files(i).name ;
fid = fopen(filename, 'r');
ZWD = fscanf(fid, '%f');
T = [T; ZWD];
catch ME
disp('An error occurred while processing the files.');
disp('Execution will continue.');
continue
end
end
0 Kommentare
Akzeptierte Antwort
KSSV
am 10 Jun. 2021
files = dir('*.txt') ; % you are in the folder of files
N = length(files) ;
T = cell(N,1);
for i = 1:N
filename = files(i).name ;
fid = fopen(filename, 'r');
data = fscanf(fid, '%f');
T{i} = data ;
end
iwant = cell2mat(T) ;
4 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!