How to input a string of integers and hex values together as an input. [9,0xa,0xb]

3 ビュー (過去 30 日間)
WARRIOR24
WARRIOR24 2020 年 12 月 15 日
コメント済み: Steven Lord 2020 年 12 月 15 日
1.) I am trying to make this string [0,1,2,3,4,5,6,7,8,9,0xA,0xB] as an input the convert to decimal value and/or binary?
Is this possible?
0xA = 10
0xB = 11
they are both Hex inputs.
2.) Then I am trying to convert this string of values to Chars.
Here is what I am got so are with the error:
Array = [0,1,2,3,4,5,6,7,8,9,0xa,0xb]
Array = dec2hex(Array)
Array = convertStringsToChars(Array)
Here is the output showing on the command window.
>> untitled2
Error: File: untitled2.m Line: 12 Column: 32
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax
error. To construct matrices, use brackets instead of parentheses.
  3 件のコメント
WARRIOR24
WARRIOR24 2020 年 12 月 15 日
change it dec, then to binary, then combine all binary values
'0000 0001 0010 00010'
but with no spaces and continous. Basically make it into a 32bit vector
'00000001001000010'
I need to do some binary computation
James Tursa
James Tursa 2020 年 12 月 15 日
編集済み: James Tursa 2020 年 12 月 15 日
What I mean is that for this specific example you gave:
Array = [0,1,2,3,4,5,6,7,8,9,0xa,0xb]
which contains 12 double values, what exactly is your desired output? I don't mean a description ... I mean the exact output you want for that exact input.

サインインしてコメントする。

回答 (2 件)

Matt Gaidica
Matt Gaidica 2020 年 12 月 15 日
reshape(dec2bin(Array),1,[])
  7 件のコメント
Matt Gaidica
Matt Gaidica 2020 年 12 月 15 日
I'm not sure what's going on. The attached file results with:
Array =
1×12 uint8 row vector
0 1 2 3 4 5 6 7 8 9 10 11
ans =
'000000001111000011110000001100110011010101010101'
ans =
'000000000000000000000000000000000000000000000000000000001111000011110000001100110011010101010101'
I'm running MATLAB 2020b. My hex numbers do not have the red warning underneath them. Perhaps try: 0xA, 0xB?
WARRIOR24
WARRIOR24 2020 年 12 月 15 日
Still the same result, I am running 2020a

サインインしてコメントする。


Steven Lord
Steven Lord 2020 年 12 月 15 日
If you're using release R2019b or later this should work. This confirms it works in release R2020b.
Array = [0,1,2,3,4,5,6,7,8,9,0xa,0xb]
Array = 1×12
0 1 2 3 4 5 6 7 8 9 10 11
From the fact that Code Analyzer flags this as an error, are you certain you're using release R2020a? Can you post the output of this command in your installation of MATLAB to confirm that?
version
ans = '9.9.0.1544872 (R2020b) Update 3'
  3 件のコメント
Rik
Rik 2020 年 12 月 15 日
Jan's answer should work for you.
Steven Lord
Steven Lord 2020 年 12 月 15 日
Because you're using the release before the capability to enter hex literals was introduced, you will not be able to type 0xa and have MATLAB turn that into uint8(10). As Rik suggested see Jan's answer, or if you're going to want to use this new functionality look at the Release Notes and consider if upgrading to a newer release is an option.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by