Textscan Importing Multiple Inputs From One Text File
显示 更早的评论
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 个评论
Stephen23
2021-5-4
" 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
2021-5-4
回答(1 个)
S = readlines('ResultA3forMatlabv2.txt');
F = @(s)sscanf(s,'%f,');
C = arrayfun(F,S,'uni',0)
C{1:3} % the first few lines
类别
在 帮助中心 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!