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

3 次查看(过去 30 天)
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 个评论
Adam Danz
Adam Danz 2020-1-12
编辑:Adam Danz 2020-1-12
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 2020-1-12
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-1-12
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};

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by