How To Get Number Of Columns in Non-Rectangular Array of Data for textscan Function
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I am currently using the following line of code for extracting data from a csv file, which contains non-rectangular array of data
C = textscan(fileID, repmat('%f',[1 22]), Delimiter, ',', 'EmptyValue', NaN);
What I would love to do is replace that 22 with a variable. Right now I need to check the csv, count the columns (currently, 22) and enter that number manually. Is there a way I could automate that and replace 22 with a variable, eliminating the need to look in the csv file in the future?
Thanks
0 个评论
回答(1 个)
Star Strider
2017-4-19
Since your files don’t appear to have header lines, the xlsread or csvread functions might be more appropriate than textscan to import your files.
4 个评论
Star Strider
2017-4-19
My pleasure.
I’ve found textscan to be rather robust to (my) stretching it beyond its intended limits. In any event, you can always comment your code (good practice anyway) to check your textscan call if your code starts behaving strangely.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!