how to add a column as input for hexadecimal to decimal/binary conversion

2 views (last 30 days)
i have a table of ascii codes which i need to convert them to decimal or binary format to decode it. but im not able to give the columns of the table as input for conversion. is there a way to do so?
i have used the following code:
B = T(T.message=='18FF0803x',:);
columns = B(:,3:end);
first_column1 = columns(:,1);
first_column1 = hex2dec(first_column1);
And, im getting the following error-
Error using hex2dec (line 30)
Input to hex2dec must be a character vector, string, or cell array of character vectors.
  2 Comments
Adam Danz
Adam Danz on 12 Jan 2020
Edited: Adam Danz on 12 Jan 2020
It's clear that the message column contains hexidecimal char arrays or strings but we have no idea what's in the 3rd column of your table (the column causing the error). We do know that whatever is in that column, it's not a char vector, string or cell array of char vectors.
Could you show us the result of
head(T)
Also, the correct way to identify string matches is by using strcmp()
B = T(strcmp(T.message,'18FF0803x'),:);
dpb
dpb on 12 Jan 2020
We can't tell what B contains because we don't have T or even an example of it.
We don't know for sure B isn't empty, even...
Attach a sample part of the data...
Whatever B is, the message is telling you the third column isn't a valid hex string representation that hex2dec can work on.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Jan 2020
B = T(T.message=='18FF0803x',:);
T is a table() object, so extracting some rows of it gives a table object.
columns = B(:,3:end);
Extracting columns from a table object give a table object.
first_column1 = columns(:,1);
Extracting one column for a table object gives a table object.
first_column1 = hex2dec(first_column1);
hex2dec cannot process table objects.
first_column1 = columns{:,1};

More Answers (0)

Categories

Find more on MATLAB Report Generator in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!