Finding if the value is present in the table using readtable

4 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Voss
Voss el 28 de Jun. de 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 comentarios
Voss
Voss el 10 de Jul. de 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')
ans = logical
0
ismember(testnode(3),'a':'f')
ans = logical
1
testnode='0x43336'; % digit
ismember(testnode(3),'0':'9')
ans = logical
1
ismember(testnode(3),'a':'f')
ans = logical
0
Another way:
testnode='0xc3336'; % letter
isstrprop(testnode(3),'digit')
ans = logical
0
isstrprop(testnode(3),'alpha')
ans = logical
1
testnode='0x43336'; % digit
isstrprop(testnode(3),'digit')
ans = logical
1
isstrprop(testnode(3),'alpha')
ans = logical
0
Padmapriya Sampathkumar
Padmapriya Sampathkumar el 10 de Jul. de 2022
Hey thanks. I tried the first option. I had the same logic but misssed the string notation as '0':'9'. I wrote 0:9. Thats why I didnot get the results. Thanks again for your time.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by