How to compare an excel cell with a particular data and find the index
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
lydie Nsangou
el 9 de Mzo. de 2021
Comentada: lydie Nsangou
el 31 de Mzo. de 2021
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 comentarios
Respuesta aceptada
Vineet Joshi
el 23 de Mzo. de 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 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!