Having trouble finding a row in a table
Afficher commentaires plus anciens
%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 commentaires
VBBV
le 6 Avr 2023
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
le 6 Avr 2023
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:
Réponse acceptée
Plus de réponses (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
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!