How to get the index of a row from a range of values in an excel file?

7 vues (au cours des 30 derniers jours)
yashvin
yashvin le 12 Juin 2015
Commenté : yashvin le 13 Juin 2015
I have a table in excel with 6 column values, namely A,B,C,D,E,F
Given that I specify A=50, C=59500, E=0.786
How do i find the rows in the table that contain these corresponding numbers?
See attached file Thanks

Réponse acceptée

Guillaume
Guillaume le 12 Juin 2015
Modifié(e) : Guillaume le 12 Juin 2015
You could use ismember if you want exact comparison (i.e your 0.786 is to be found exactly in the spreadsheet down to the last decimal value).
New in R2015a is ismembertol that allows to specify a tolerance which works better for floating point number (bearing in mind that for computers 0.1 + 0.1 + 0.1 is not equal to 0.3, when using double or single precision numbers).
m = xlsread('somefile.xlsx');
A = 50; C = 59500; E = 0.786;
rows = find(ismember(m(:, [1 3 5]), [A C E], 'rows')); %find exact values
%or
rows = find(ismembertol(m(:, [1 3 5]), [A C E], 1e-4, 'ByRows', true)); %find values within tolerance
edit: a few typos
  4 commentaires
Guillaume
Guillaume le 12 Juin 2015
links to doc were provided for you to work out the syntax yourself.
Anyway, fixed the typos. It should work now.
yashvin
yashvin le 13 Juin 2015
Thanks! Works perfectly. I also tried with intersect. All good!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by