Finding if the value is present in the table using readtable
68 views (last 30 days)
Show older comments
Padmapriya Sampathkumar
on 28 Jun 2022
Commented: Padmapriya Sampathkumar
on 10 Jul 2022
Hi,
I have a taken an excel file under the readtable. I have chosen of the columns (say 5th ) and takien it as a vector. The column consits of address with 42 literals (I am representing IP address). My next step is that I am asking the user to input an address and check if the address is present in the column vector of more than 3000 datasets containing the 3000 addresses. My question is that if I input an address, how do I check if that address is present in the given column vector. For example
1) My table containing 3000 datasets is A= readtable('dataset1.xlsx');
2)from_node1 = A(:,5);
I am taking up the 5th column containing address like "0x0067f95a79c3c404a9d128168ddfdf3cb70c0852", "0xe7844a3cbc712652fb97f6170603fd7d4b1cd6f1" etc
3) I am asking the user to input an address say using : testnode=input("Enter the node address");
4) Say if I want to check if "0x0f9d959667be0fd0bd2917feba0aab7ac4ca9ce7" is present in the chosen column from the table A, the output should be '0'.
How do I code this in Matlab. Your help is much appreciated. Thanks for your time.
0 Comments
Accepted Answer
Voss
on 28 Jun 2022
Try this:
A = readtable('dataset1.xlsx');
% use 's' argument in input(), so that the user input
% is stored directly in testnode and not interpreted:
testnode = input("Enter the node address", 's');
output = ismember(testnode,A{:,5}); % use {} not ()
11 Comments
Voss
on 10 Jul 2022
testnode(3) is a single character, always.
Here's one way to make a decision based on whether that character is a digit ('0' - '9') or a letter ('a' - 'f'):
testnode='0xc3336'; % letter
ismember(testnode(3),'0':'9')
ismember(testnode(3),'a':'f')
testnode='0x43336'; % digit
ismember(testnode(3),'0':'9')
ismember(testnode(3),'a':'f')
Another way:
testnode='0xc3336'; % letter
isstrprop(testnode(3),'digit')
isstrprop(testnode(3),'alpha')
testnode='0x43336'; % digit
isstrprop(testnode(3),'digit')
isstrprop(testnode(3),'alpha')
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!