其實我試圖將十六進制轉換爲bin。如何將'1 * 1 char'轉換爲MATLAB中的邏輯向量?
a=hex2dec('ab32');
a=dec2bin(a);
%now I have a 1to1 char array of for example 1010101...
%I want to have an 1*16 array of 1 and 0's
我該怎麼做?
其實我試圖將十六進制轉換爲bin。如何將'1 * 1 char'轉換爲MATLAB中的邏輯向量?
a=hex2dec('ab32');
a=dec2bin(a);
%now I have a 1to1 char array of for example 1010101...
%I want to have an 1*16 array of 1 and 0's
我該怎麼做?
你可以這樣做:
a=logical(a-'0')
例子:
octave:224> a=hex2dec('ab32')
a = 43826
octave:225> a=dec2bin(a)
a = 1010101100110010
octave:226> a=logical(a-'0')
a =
1 0 1 0 1 0 1 1 0 0 1 1 0 0 1 0
octave:227> whos a
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
a 1x16 16 logical
Total is 16 elements using 16 bytes
octave:228>
就是這樣。謝謝保羅 – 2012-07-06 12:57:10
其實你甚至不需要'真正' - 我會更新答案。 – 2012-07-06 12:59:00
這給你雷亞爾的1 * 16載體,所有0或1:
(dec2bin(hex2dec('ab32'))-'0')
而這給你一個1 * 16的邏輯矢量,全部爲假或真(看起來像0和1)
(dec2bin(hex2dec('ab32'))-'0')==1
現在不能測試這個,所以我沒有發佈它作爲答案,但你有沒有嘗試將數組轉換爲['int8'](http://www.mathworks.com) /help/techdoc/ref/int8.html)或'uint8'什麼的? – JAB 2012-07-06 12:58:39