Find string in excel file

Hello
i have got an excel file with this coloum example:
T_DCT_PK_WDT_W01B1_RANGE
T_DCT_PK_WDT_W01B2_RANGE
T_DCT_PK_WDT_W02B1_RANGE
T_DCT_PK_WDT_W02B2_RANGE
and so on.
Now i would like to search for example T_DCT_PK_WDT_W01B2_RANGE
So if(T_DCT_PK_WDT_W01B2_RANGE is found) then ....
how can i do this? This doesnt work for me:
num = xlsread ( 'T_APC_RUNKEYNUMBER_test.xlsx' );
k = strfind(num, 'T_DCT_PK_WDT_W01B2_RANGE');

Respuestas (2)

Paolo
Paolo el 25 de Jun. de 2018
Editada: Paolo el 25 de Jun. de 2018

0 votos

text = {'T_DCT_PK_WDT_W01B1_RANGE';
'T_DCT_PK_WDT_W01B2_RANGE';
'T_DCT_PK_WDT_W02B1_RANGE';
'T_DCT_PK_WDT_W02B2_RANGE'}
indx = strcmp(text,'T_DCT_PK_WDT_W01B2_RANGE')
if any(indx)
%your logic
end

9 comentarios

Adrian Pielmeier
Adrian Pielmeier el 25 de Jun. de 2018
why are u doing the text={...} i need to find the strings in my excel coloum this is how i read it:
[fileName,dirName]=uigetfile('T_APC_RUNKEYNUMBER_test.xlsx.xlsx');
[~,~,rawData] = xlsread(fullfile(dirName,fileName));
Paolo
Paolo el 25 de Jun. de 2018
It was an example, I assumed that you had read the excel file successfully already. You should be able to replace 'text' with raw.
From the documentation for raw:
Numeric and text data from the worksheet, returned as a cell array.
Adrian Pielmeier
Adrian Pielmeier el 25 de Jun. de 2018
replacing the text with rawData i get the following error
Error using strfind Cell input must be a cell array of strings.
Paolo
Paolo el 25 de Jun. de 2018
Do you have numerical values in your data, too?
Adrian Pielmeier
Adrian Pielmeier el 25 de Jun. de 2018
this is how my excel looks like this is a screenshot from the matlab clicking workspace/rawData
Paolo
Paolo el 25 de Jun. de 2018
Search for the string in the first column only, raw(:,1)
Adrian Pielmeier
Adrian Pielmeier el 25 de Jun. de 2018
Now it looks like this:
[fileName,dirName]=uigetfile('T_APC_RUNKEYNUMBER_test.xlsx');
[~,~,rawData] = xlsread(fullfile(dirName,fileName));
rawData (:,1);
indx = strcmp(rawData,'T_DCT_PK_WDT_W01B1_RANGE');
if any(indx)
fprintf('Correct');
end
but eventho there is a cell with T_DCT_PK_WDT_W01B1_RANG there is no printf
Paolo
Paolo el 25 de Jun. de 2018
indx = strcmp(rawData(:,1),'T_DCT_PK_WDT_W01B1_RANGE');
Rohan Singla
Rohan Singla el 29 de Abr. de 2020
can we also find the row and column number at which our string was present?

Iniciar sesión para comentar.

Ahmed Elsherif
Ahmed Elsherif el 23 de Nov. de 2018

0 votos

Hi,
I have something similar as I am looking for a value under a certain header in GUI. In principle, it works but it prints a wrong value! I mean it shows the value in the third column after the desired one although it prints '1' for the correct position.
Whould you please help me why?
Thanks in advance.
My sub-code is:
handles.fileName = uigetfile ('.xlsx')
[data, text] = xlsread('input');
idx = strcmpi(text(1,:),'headertobefound')
k=data(:,idx);
set(handles.edit40,'string',k);

Etiquetas

Preguntada:

el 25 de Jun. de 2018

Editada:

el 29 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by