How to compare an excel cell with a particular data and find the index
11 次查看(过去 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
0 个评论
采纳的回答
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 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 Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!