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
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
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
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 Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!