how to add a column as input for hexadecimal to decimal/binary conversion
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Padmamalini T H
le 12 Jan 2020
Commenté : Padmamalini T H
le 20 Jan 2020
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 commentaires
Adam Danz
le 12 Jan 2020
Modifié(e) : Adam Danz
le 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
le 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.
Réponse acceptée
Walter Roberson
le 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};
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!