gpt4 book ai didi

matlab - 如何在 MATLAB 中将 '1*1 char' 转换为逻辑向量?

转载 作者:行者123 更新时间:2023-12-02 06:17:23 26 4
gpt4 key购买 nike

实际上我正在尝试将十六进制转换为二进制。

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>

关于matlab - 如何在 MATLAB 中将 '1*1 char' 转换为逻辑向量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11362504/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com