Having trouble finding a row in a table
古いコメントを表示
%I'm trying to load this table and then search for a number within the first column, then load that entire row, I can get it if I use this example: table(5,[1:5]) manually, but cannot get my input to be found and then given to me. I get this error "Operator '==' is not supported for operands of type 'table'." and " Error in e=find(a(:,1)==X);"
load('table.mat');
X=input('What would you like to know?: ');
row=find(table(:,1)==X);
disp('The properties at this temperature are:');
table(row,[1:5])
2 件のコメント
VBBV
2023 年 4 月 6 日
You show the error as
Error in e=find(a(:,1)==X);
but use a different variable name here
row=find(table(:,1)==X);
Any reason why you have different variable names a and table in different places of code? Please show relevant code and /or data
Image Analyst
2023 年 4 月 6 日
Three people (below) have tried to help you but it seems like we're spinning out wheel because you keep forgetting to attach your table. If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
採用された回答
その他の回答 (1 件)
You need to extract the contents of the table variable if you want to use == on it in the release you're using.
load patients
T = table(LastName, Height, Weight);
firstTenRows = T(1:10, :)
Let's find the patients that are 68 inches tall.
patients68 = firstTenRows.Height == 68; % or
patients68 = firstTenRows{:, 'Height'} == 68;
selectedPatients = firstTenRows(patients68, :)
If you were using release R2023a or later and all the data in your table supported the == operator you could directly perform certain math operations on the table.
justHeightAndWeight = firstTenRows(:, ["Height", "Weight"])
justHeightAndWeight(:, "Height") == 68
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!