Hi Arya C,
I understand that you have a variable and an Excel file, and your objective is to compare the values in the table with the corresponding columns. Once a match is found, you intend to print the entire row that contains the matching values.
To achieve this, you can do the following:
- Read the Excel file and store it in a variable named ‘excel_data’ as a table using ‘readtable’ function.
excel_data = readtable("excel_data.xlsx") ;
- Store the data from relevant columns (3 to 8) in a 2-D array named ‘rel_data’.
rel_data = excel_data{:,3:8};
- Convert the data in your variable to a ‘1x6 Array’.
arr_data = variable_name{1,:};
- Use the ‘ismember’ function to match the data with excel file and ‘find’ function to get the index.
ind = find(ismember(rel_data,arr_data,'rows'));
- Using this index and the table, you can print the corresponding row.
Please note that if there is no matching data then ‘ind’ will be of size ‘0x1’.
You can go through the below documentation for more details.
I hope this answer helps.