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

 Accepted Answer

Rik
Rik on 12 Aug 2018
Edited: Rik on 12 Aug 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 Comment

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

Sign in to comment.

More Answers (0)

Categories

Asked:

on 12 Aug 2018

Edited:

Rik
on 12 Aug 2018

Community Treasure Hunt

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

Start Hunting!