Using dec2hex within a pattern
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi:
In the attached file, I am counting the occurrence of matched strings in columns 2, 3, and 6. The element in TN_Hex is searched in column 2, the elements in DS_Hex are searched in column 3, and the string 'Hi is searched in column 6.
In my case, I want to enter the elements of set TN_Hex in its decimal form as shown in TN_Dec, and the elements in DS_Hex to its decimal form as in DS_Dec. Note the pattern "fe80::c30c:0:0:...", which is what I have in the xls file. I am thinking to use dec2hex for the elements in TN_Dec, and DS_Dec and put it in the space of the pattern "fe80::c30c:0:0:..." and perform the occurrence counting. In other words I want to avoid entering elements in the lengthy way, the Hex form, since the set might contain too many elements.
The code below finds the occurrence of patterns in columns 2, 3, and 6
clc; clear;
TN_Dec={'1'};%The preferred way
TN_Hex = {'fe80::c30c:0:0:1'};
DS_Dec={'15','16','17','18','19','20'};%The preferred way
DS_Hex = {'fe80::c30c:0:0:F','fe80::c30c:0:0:10','fe80::c30c:0:0:11','fe80::c30c:0:0:12','fe80::c30c:0:0:13','fe80::c30c:0:0:14'};
[num,txt,raw] = xlsread('Example.xls');
Col2= cellfun(@num2str,raw(:,2),'uni',0);
Col3= cellfun(@num2str,raw(:,3),'uni',0);
Col6= cellfun(@num2str,raw(:,6),'uni',0);
idx = strcmp(Col2,TN_Hex) & ismember(Col3,DS_Hex) & strcmp(Col6,'Hi');
Numofoccurrence=nnz(idx);
I appreciate your suggestions.
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!