필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
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

채택된 답변

Vineet Joshi
Vineet Joshi 2021년 3월 23일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by