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 日

1 投票

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 件のコメント

Nigel lancaster
Nigel lancaster 2018 年 8 月 12 日
編集済み: Nigel lancaster 2018 年 8 月 12 日
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 ExchangeCharacters and Strings についてさらに検索

質問済み:

2018 年 8 月 12 日

編集済み:

Rik
2018 年 8 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by