MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何在MATLAB中转换8位二进制值的大型数组? (https://www.labfans.com/bbs/showthread.php?t=22837)

poster 2019-12-10 16:49

如何在MATLAB中转换8位二进制值的大型数组?
 
这是[URL="https://stackoverflow.com/questions/1544456/faster-version-of-dec2bin-function-for-converting-many-elements"]我的另一个SO问题的[/URL]后续[URL="https://stackoverflow.com/questions/1544456/faster-version-of-dec2bin-function-for-converting-many-elements"]问题[/URL] 。

我有一个很大的8位二进制值数组,我想将其转换回uint8。

我已使用上一个问题中的Amro的lookupTable解决方案。现在,我想做相反的事情。我想做一个查询表,但可惜我做不到。

我设法做到以下几点:

temp = ones([(TotalPixel),1], 'uint8'); for iter2 = 1 : TotalPixel, temp(iter2,1) = sum(Data(iter2,1:8).*2.^(7:-1:0)); end 但是for循环太慢,因为它需要2秒来转换[76800 x 1]数组。有没有更好/更快的方法来做到这一点?


回答:
尝试这个:

temp = uint8(Data*(2.^(7:-1:0))'); 请注意,该答案与[URL="https://stackoverflow.com/questions/1552966/converting-binary-to-decimal-without-using-loop/1554876#1554876"]我对[/URL]您[URL="https://stackoverflow.com/questions/1552966/converting-binary-to-decimal-without-using-loop"]之前提出的问题[/URL] [URL="https://stackoverflow.com/questions/1552966/converting-binary-to-decimal-without-using-loop/1554876#1554876"]的答案所做的编辑[/URL]基本相同。您曾问过有关仅转换一行12位值的问题,但是我添加了额外的讨论,讨论如何将其扩展为使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/mtimes.html"]矩阵乘法[/URL]一次转换多个值。答案与答案之间的区别仅仅是位数和包含[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/uint8.html"]UINT8[/URL]来更改变量类型。



[url=https://stackoverflow.com/questions/1595030]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:21

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.