Import data from Excel, based on the cell content

I want to import a set of data corresponding to a particular cell value, for example,
Here, I want the select all the data where AD=2.57 and delete the rest of the data.

 Réponse acceptée

dpb
dpb le 16 Juin 2016
Wrong approach -- read the data, then eliminate that which isn't wanted.
x=xlsread('yourfile.xls');
x=x(x~=5);
If you need to know from whence they came then either
[ir,ic]=find(x==5); % row, column indices
ix=(x==5); % logical array
before removing the values.
Otherwise, if adamant, use ActiveX and it becomes a question of Excel syntax, not Matlab...

3 commentaires

I have given a better example of my situation. Please see, thanks!
Same answer still holds except read the column of interest...
[~,shts]=xlsfinfo('yourfile.xls'); % get sheet name
x=xlsread('yourfile.xls',char(shts),'AD:AD'); % read the column
Previous as before for the value of interest; you may need the tolerance to test a floating point value for equality to within a small difference owing to fp rounding issues.
Thank you! That solved my problem!

Connectez-vous pour commenter.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 16 Juin 2016
Modifié(e) : Azzi Abdelmalek le 16 Juin 2016

0 votes

Use xlsread to import your data, then take what you want. I think what you want is to locate the number 5 for example in your matrix.

1 commentaire

I have given a better example of my situation. Please see, thanks!

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by