reading CSV files with multiple rows of strings and multiple rows of floats
6 次查看(过去 30 天)
显示 更早的评论
The first four rows [1:4] of my csv are strings. The remaining rows [5:inf] are numerical data. I need to import all rows, preferably into a table. How can I do this with readtable (or other function). I don't see any way in the opts file. I am probably missing something.
2 个评论
回答(2 个)
Steven Lord
2025-8-11
All the data in a variable in a table must be the same type. You can't have one where the first four rows are text and the next four rows are numbers.
Depending on what you're planning to do, reading the first four rows into a table then reading in the next rows as a separate table, transforming each row of each of those tables into variables using rows2vars, and then concatenating them side-by-side may be suitable for your needs.
t1 = table("abc", "def", "ghi", "jkl", RowNames = "id")
t2 = array2table(magic(4))
t1a = rows2vars(t1)
t2a = rows2vars(t2)
T = [t1a(:, "id"), t2a(:, 2:end)]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!