필터 지우기
필터 지우기

Convert Logical Column to Table

조회 수: 9 (최근 30일)
Theodore
Theodore 2023년 3월 11일
답변: Star Strider 2023년 3월 11일
How does one append a Nx1 logical to the right of a Nx4 table?
I assumed this would be a matter of horzcat(initialTable, logicalColumn)
But, I recieve an error of "All input arguments must be tables."
So the real question is:
how to convert the Nx1 logical column to a "table", such that I can horzcat the tables?
Thank you

채택된 답변

Star Strider
Star Strider 2023년 3월 11일
Use the addvars function —
T1 = array2table(rand(10,4), 'VariableNames',{'A','B','C','D'})
T1 = 10×4 table
A B C D _______ _______ ________ ________ 0.94355 0.46999 0.6111 0.49835 0.16236 0.77156 0.070068 0.30287 0.39682 0.21807 0.6177 0.22845 0.19572 0.73545 0.072427 0.98402 0.24671 0.24431 0.40432 0.49477 0.30326 0.28484 0.5922 0.02865 0.14205 0.33359 0.94847 0.69256 0.62436 0.21889 0.70145 0.060852 0.69664 0.75923 0.42365 0.66119 0.6537 0.12065 0.65835 0.017138
LogicalVector = rand(10,1)>0.5;
T1 = addvars(T1,LogicalVector,'After','D')
T1 = 10×5 table
A B C D LogicalVector _______ _______ ________ ________ _____________ 0.94355 0.46999 0.6111 0.49835 false 0.16236 0.77156 0.070068 0.30287 true 0.39682 0.21807 0.6177 0.22845 false 0.19572 0.73545 0.072427 0.98402 false 0.24671 0.24431 0.40432 0.49477 true 0.30326 0.28484 0.5922 0.02865 true 0.14205 0.33359 0.94847 0.69256 false 0.62436 0.21889 0.70145 0.060852 false 0.69664 0.75923 0.42365 0.66119 true 0.6537 0.12065 0.65835 0.017138 false
.

추가 답변 (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