Operands on table, comparison with numbers

7 ビュー (過去 30 日間)
Mihai Milea
Mihai Milea 2020 年 11 月 26 日
コメント済み: Mihai Milea 2020 年 11 月 27 日
Hi .I have a table after reading a csv file with readtable .I attached a sample file .Say I get a table A after reading.
say I fix one of the row indices " ind" .If I try say find(A(ind,:)>0.1) I get the error : "Operation '>' not supported for operands of type table " .In general how do I just go back to some classic matrix from a table ignoring these Variable names?
I tried table2array but with no luck .Many thanks

採用された回答

Steven Lord
Steven Lord 2020 年 11 月 26 日
say I fix one of the row indices " ind" .If I try say find(A(ind,:)>0.1) I get the error : "Operation '>' not supported for operands of type table " .In general how do I just go back to some classic matrix from a table ignoring these Variable names?
There's no guarantee you can "slice" the table across rows -- the variables may contain data of different data types.
load patients
T = table(LastName, Gender, Age, Smoker);
head(T)
ans = 8x4 table
LastName Gender Age Smoker ____________ __________ ___ ______ {'Smith' } {'Male' } 38 true {'Johnson' } {'Male' } 43 false {'Williams'} {'Female'} 38 false {'Jones' } {'Female'} 40 false {'Brown' } {'Female'} 49 false {'Davis' } {'Female'} 46 false {'Miller' } {'Female'} 33 true {'Wilson' } {'Male' } 40 false
But if you can, you can use curly braces to extract the data into a numeric array.
A = magic(4)
A = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
T2 = array2table(A)
T2 = 4x4 table
A1 A2 A3 A4 __ __ __ __ 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
T2{3, :} % The same as A(3, :)
ans = 1×4
9 7 6 12
  1 件のコメント
Mihai Milea
Mihai Milea 2020 年 11 月 27 日
Did not work this way but your answer works fine with readcell instead od readtable -:))

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2020 年 11 月 26 日
You have to access the columns of Table T using T.(1), T.(2) etc,
Read about accessing the columns from tatble. If you have names to the columns, you can use
T.col1, T.col2 etc to access the respective columns.
  3 件のコメント
KSSV
KSSV 2020 年 11 月 26 日
Use xlsread and get all the data into a matrix.
Mihai Milea
Mihai Milea 2020 年 11 月 26 日
Does not read this csv file .readcell works but instead of table I get some cell structure which gives the same error

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by