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

 采纳的回答

Rik
Rik 2018-8-12
编辑:Rik 2018-8-12
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 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by