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!