Xlsread for a particular column returns values from another column too?

Hello,
I want to obtain the row indices of cells from the Column AD with a particular value, Column X with a particular value, and get the common indices in another array.Here's the code I used:
%Read data1 and select files with the corresponding value
MyData1=xlsread(FileName,'AD:AD'); % read the column
[ir,ic]=find(MyData==2.5); % row, column indices
%Read data 2 and select files with the corresponding value
MyData2=xlsread(FileName,'X:X'); % read the column
[er,ec]=find(MyData2==49);
%Select common files
files=intersect(ir,er);
But, I am getting indices of rows that have these values from another column, here AA. Which I have not specified anywhere. Is there any error in my code?
Thank you.

5 Comments

Me no follow...if you want column 'AD' what does 'X' have to do with it (and vice versa)??? Looks like you got what you asked for (with the possible exception of the exact FP compare problem mentioned in the previous thread)...
Hi, sorry about that, I was confused. I put it in a better way, tell me if you understand. Thank you!
Well, it's not possible to diagnose the problem without the .xls file; there doesn't appear to be any coding error in the code snippet you've shown; xlsread is documented to read a range without a sheet name when given a 'C1:C2' range so afaik the 'C:C' specification works in what testing I've done here. You can try the other respondent's suggestion (as mine in the previous thread) of using the explicit sheet name and see if that does solve anything but my guess is it won't because that's not the issue but it is something beyond what's shown here.
Alternatively, and perhaps still as fast or faster than opening the spreadsheet twice with xlsread, use it only once and read the full sheet (or the range 'X:AD' and then use array indexing in memory to address the wanted columns (which would be more nearly "the Matlab way" as I've also alluded to in previous thread).
How do you know something came from column 'A', btw, and not the issue as mentioned earlier regarding floating point comparison or other unknown issues?
Hi,
I fixed this by just selecting the larger set of elements from the column which I need. But if you do find a solution for this situation, feel free to post it. Thank you.
I don't think there is a "situation"; I think there's an error somewhere in the previous work outside what was posted here that we could see that explains the problem you're having.

Sign in to comment.

Answers (1)

MyData1 = xlsread(fileName,'Sheet1','AD:AD');
ir = find(ismember(MyData1,2.5));
MyData2 = xlsread(fileName,'Sheet1','X:X');
er = find(ismember(MyData2,49));
files=intersect(ir,er);

Categories

Asked:

on 17 Jun 2016

Edited:

on 18 Jun 2016

Community Treasure Hunt

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

Start Hunting!