How do I table a variable with multiple values?

조회 수: 16 (최근 30일)
Chesus
Chesus 2023년 8월 31일
댓글: Chesus 2023년 8월 31일
I have a variable with multiple values
x= -10:1:10
and I want to put it in a table, with each value being in one row of the table, but when I introduce the command the following happens:
table(x)
And when I try to use splitvars it creates more variables instead of rows
How can I do so the values of x are displayed on rows?
  댓글 수: 1
Chesus
Chesus 2023년 8월 31일
Also, one thing to mention, if I put every value of x manually the table does work, but I don't want to do that as I want to change later the range of x
x= [-10;-9;-8;-7;-6;-5;-4;-3;-2;-1;0;1;2;3;4;5;6;7;8;9;10]

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2023년 8월 31일
x= -10:1:10
x = 1×21
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10
T1 = table(x.', 'VariableNames', {'x'})
T1 = 21×1 table
x ___ -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5
%or
x = x(:);
T2 = table(x)
T2 = 21×1 table
x ___ -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by