How to compare an excel cell with a particular data and find the index

5 visualizzazioni (ultimi 30 giorni)
Hi can someone please help me!
i have an excel file containing multiple rows and columns .i want to go through a particular column and check row after row if any element of that column matches with my Data2.
Data2 here is a cell containing names eg Data2 = {'BAR23','LY46','BER35',Aal23'','JO234'}. and if Data2 matches to any row of my specified column ,i would like to know the index of the row iand read the elements of that row in to matlab
thanks in advance
line_start=1;
line_stop=50;
names='B';
sheet = 1;
range_names=[column_profile_names num2str(line_start) ':' column_profile_names num2str(line_stop)];
file ='C:\Users\MIX\Documents\Example.xlsx';
[~,profile_names,raw]=xlsread(file,sheet,range_names,'basic');
Data2 = {'BAR23','LY46','BER35',Aal23'','JO234'}
for i=1:length(profile_names)
index = find( strcmp(profile_names,Data2));
end
this is what i have till yet
i always get the error ! indice exceeds matrix dimension

Risposta accettata

Vineet Joshi
Vineet Joshi il 23 Mar 2021
As per my understanding of your question, you want to find indices of rows in a particular column with data from the Data2 cell.
You can use the ismember function.
You can refer the following sample excel file & sample code for reference.
%Load the file.
file ='Example.xlsx';
[~,TestCols,~]=xlsread(file);
%Given Cell.
Data2 = {'BAR23','LY46','BER35','Aal23','JO234'};
%Check In Column 4.
ismember(TestCols(:,4),Data2)
%Output
ans =
10×1 logical array
0
1
0
1
1
0
1
0
0
0
%Check in Column 5
ismember(TestCols(:,5),Data2)
%Output
ans =
10×1 logical array
0
1
0
0
1
1
0
0
1
1

Più risposte (0)

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Prodotti


Release

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by