
Import data as a cell array in a script
14 次查看(过去 30 天)
显示 更早的评论
I need to import data as a cell array to Matlab for many files and later perform some operations to them. Is there any way I can import the data in a script to do it automatically instead of manually?
What I do manually is:
-Home > Import Data
-Choose .txt file
-As a cell array, 2 columns as text.
-Column delimiters: comma.
Thank you
0 个评论
采纳的回答
Sean de Wolski
2015-2-9
编辑:Sean de Wolski
2015-2-9
Zynk, in the import tool, after you make your selections, there's an option to "Generate function". You could then use this function on all of your files by looping over the filenames.

更多回答(2 个)
Star Strider
2015-2-6
You do not give the actual file format or the file itself, so I cannot provide exact code. I would use the textscan function.
A possible (untested) way to code it would be:
fidi = fopen( filename );
data = textscan(fidi, '%f%f', 'Delimiter',',');
Be sure to explore the other name-value pair arguments if necessary.
3 个评论
Star Strider
2015-2-9
The ‘table’ functions are a more efficient solution, but they were introduced with R2013a, and not everyone has access to them. Unless I know the version people are using, I go with the most generic solution possible.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!