how to compare matlab output with excel data

5 次查看(过去 30 天)
i got some feature values as matlab output.i have those values in my excel data.i want to match these values and print the correponding row of excel file as matlab output.my excel file is as above.and i my matlab output is also attached.can i get the code for that.

回答(1 个)

vidyesh
vidyesh 2023-10-3
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") ; % It is assumed the name of excel file is 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.
disp(excel_data(ind,:))
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.

Community Treasure Hunt

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

Start Hunting!

Translated by