相关疑难解决方法(0)

更快版本的dec2bin函数用于转换多个元素?

我正在读取位图文件并将每个 RGB值从0到255转换为二进制.

因此240 x 320位图将具有230400个RGB值进行转换.原来的dec2bin函数太慢了,所以我写了自己的函数,因为我知道我的值总是在0到255之间.

但是,通过230400值仍将需要大约.在我的机器上6秒,单色位图大约需要2.3秒.

无论如何,加速到1秒甚至更好的0.5秒,因为我的应用程序每msec计数?

这是我的代码:

function s = dec2bin_2(input)

if input == 255
    s = [1;1;1;1;1;1;1;1];
    return;
end

s = [0;0;0;0;0;0;0;0];

if input == 0
    return;
end

if input >= 128
    input = input - 128;
    s(1) = 1;
    if input == 0
        return;
    end
end

if input >= 64
    input = input - 64;
    s(2) = 1;
    if input == 0
        return;
    end
end

if input >= 32
    input = input - 32;
    s(3) = …
Run Code Online (Sandbox Code Playgroud)

binary matlab

8
推荐指数
1
解决办法
4376
查看次数

十进制到二进制为双类型数组,而不是字符串

到目前为止我有这个:

data = 14
out = dec2bin(data, 4)
Run Code Online (Sandbox Code Playgroud)

这使:

out = 1110
Run Code Online (Sandbox Code Playgroud)

但我希望以这种格式获得二进制数:

out = [1 1 1 0]
Run Code Online (Sandbox Code Playgroud)

感谢帮助!

binary matlab octave

4
推荐指数
1
解决办法
180
查看次数

标签 统计

binary ×2

matlab ×2

octave ×1