How do I create a table containing a character array if it has only one row?
조회 수: 71 (최근 30일)
이전 댓글 표시
This works fine:
Time = [1;2];Force = [12;17];ID = ['ab';'cd'];
T = table(Time,Force,ID)
But this fails:
Time = [1];Force = [12];ID = ['ab'];
T = table(Time,Force,ID)
There may be a good reason for this, but the behaviour does not seem logical to me.
Does anyone have good workaround?
댓글 수: 1
Stephen23
2022년 3월 4일
"There may be a good reason for this"
Yes: single character vectors are presumed to be part of name-value arguments.
채택된 답변
Simon Chan
2022년 3월 4일
Time = [1];Force = [12];ID = {'ab'};
T = table(Time,Force,ID)
Actually, the error message tells you the solution.
Time = [1];Force = [12];ID = ['ab'];
T = table(Time,Force,ID)
댓글 수: 2
Csaba Zoltán Kertész
2022년 3월 13일
You could also try to use strings instead of character vectors if you do not want to hassle with cells:
Time = [1]; Force = [12]; ID = ["ab"];
T = table(Time, Force, ID)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!