Textscan Importing Multiple Inputs From One Text File

4 views (last 30 days)
Hello All,
I am trying to extract many of different data from one text file. This text file comes from Python output and there is /n after each data. Every data uses comma as a delimiter. I was trying to use the code below but it gives me the overall whole data in one column but I'd like to get separate data columns based on /n. By the way, every data can have different amount of row vector. I am also attaching a basic ss of my data, would you please help me?
fid = fopen('ResultA3forMatlab.txt','r');
datacell = textscan(fid, '%f', 'Delimiter', ',','CollectOutput',0);
fclose(fid);
  2 Comments
Stephen23
Stephen23 on 4 May 2021
" I am also attaching a basic ss of my data"
We cannot test code on your screenshot. Please upload an actual text file by clicking on the paperclip button.
Burak Duran
Burak Duran on 4 May 2021
Here is the file, the actual file will contain a total of 587 different data, this is just a small part of it. Thank you!

Sign in to comment.

Answers (1)

Stephen23
Stephen23 on 4 May 2021
Edited: Stephen23 on 4 May 2021
S = readlines('ResultA3forMatlabv2.txt');
F = @(s)sscanf(s,'%f,');
C = arrayfun(F,S,'uni',0)
C = 19×1 cell array
{3201×1 double} {3201×1 double} {3201×1 double} {7232×1 double} {7231×1 double} {7231×1 double} {3201×1 double} {3201×1 double} {3201×1 double} {4001×1 double} {4001×1 double} {4001×1 double} {6002×1 double} {6002×1 double} {6002×1 double} {6002×1 double}
C{1:3} % the first few lines
ans = 3201×1
0 -7.886307 -12.152959 -5.638267 0.884078 7.416171 13.897649 14.713729 15.461036 12.012622
ans = 3201×1
0 -0.927742 -1.542422 -2.181764 -2.787334 -3.397096 -3.975622 -4.534192 -5.088537 -5.608877
ans = 3201×1
0 0.485164 0.480764 0.474832 0.467391 0.458468 0.448094 0.436305 0.423142 0.40865

Community Treasure Hunt

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

Start Hunting!