MATLAB: Pull data from Excel sheet based on 2 conditions

excel

I have an Excel sheet that I've imported into MATLAB. In the Excel sheet, cells 2A – 5A represent condition A, while cells 1B – 1F represent condition B. Columns B-F and rows 2-5 represent values based on the 2 conditions. How do I get MATLAB to call a particular value from the Excel sheet by inputting a numerical value for conditions A and B?

Best Answer

Hi Rachel, 
I understand that you would like to access the data in a particular cell of an imported Excel spreadsheet by specifying a numerical condition for the row (condition A) and column (condition B). 
Once you import your Excel spreadsheet to a matrix in MATLAB, you can use the 'find' command to find which row and column of the matrix correspond to a particular condition. You can then index into the matrix using your desired row and column. For example: 
% Import spreadsheet data to matrix
myExcelData = xlsread('mySpreadsheet.xlsx');
% Set desired conditions
conditionA = 3.5;
conditionB = 200;
%  Find row and col of desired conditions
[row,~] = find(myExcelData == conditionA);
[ ~,col] = find(myExcelData == conditionB);
% Obtain data at desired conditions
myValue = myExcelData(row,col);
See the documentation for the 'find' function for more information and examples: