Counting a pattern frequency in a column

Hi
I am trying to count the of a pattern called "MyNode={'28'}" as shown in the code below.
clc; clear;
MyNode={'28'};
MyNode_Decimal=str2double(MyNode);
MyNode_Hex=lower(arrayfun(@(x) (dec2hex(x)), MyNode_Decimal, 'UniformOutput', false));
PatternL2={'00:00:00_00:00:'};
MyNode_L2=strcat(PatternL2,MyNode_Hex);
[~,~,raw]= xlsread('test.xlsx');
Col3= cellfun(@num2str,raw(:,3),'uni',0);
Col3_final=Col3(2:end);
cond1=strfind(Col3_final,MyNode_L2);
The corresponding string is "00:00:00_00:00:1c (00:00:00:00:00:1c) (TA)". I want to count the red colored pattern, not including the blue pattern. I used ismember, strcmp but no use, the closest is strfind but I don't get it exactly.
I really appreciate your help.
NL

 Respuesta aceptada

Rik
Rik el 12 de Ag. de 2018
Editada: Rik el 12 de Ag. de 2018
The code below will count the number of times that the pattern you describe is found in the third row of the Excel file.
MyNode={'28'};
MyNode_Decimal=str2double(MyNode);
pattern=sprintf('00:00:00_00:00:%x (00:00:00:00:00:%x) (TA)',...
MyNode_Decimal,MyNode_Decimal);
[~,~,raw]= xlsread('test.xlsx');
L=ismember(raw(:,3),pattern);
%postions=find(L);
N_found=sum(L);

1 comentario

Nigel lancaster
Nigel lancaster el 12 de Ag. de 2018
Editada: Nigel lancaster el 12 de Ag. de 2018
Hi Rik:
Thanks for your help, I just modified it at the "ismember" line as following:
L=ismember(raw(:,3),pattern);
It works fine, thanks again
NL

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 12 de Ag. de 2018

Editada:

Rik
el 12 de Ag. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by