gpt4 book ai didi

file - Matlab:如何从文件中读取二进制数?

转载 作者:行者123 更新时间:2023-12-01 00:08:42 28 4
gpt4 key购买 nike

文件包含由换行符分隔的二进制数。

$ cat bin_MCS.txt |tail
000000001100000000000010000000000
000000010010000000000010000000000
000011000000000000000000000000000
000010100000000000000000000000000
000101000000000000000000000000000
000100100000000000000000000000000
000100001000000000000010000000000
000000110000000000000010000000000
000001010000000000000010000000000
000010001000000000000010000000000

Matlab读取DEC二进制数,错误

>> textread('bin_MCS.txt')

ans =

1.0e+30 *

0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000

目标

I need to read the binary numbers to a matrix like this [1 0 1;0 1 1]. The first puzzle is to be able to read the binary numbers. Then the next puzzle is to be able to read them in a certain format.

最佳答案

读取为字符串,然后使用 bin2dec 转换为十进制数:

bin2dec(textread('bin_MCS.txt','%s'))

ans =

25166848
37749760
402653184
335544320
671088640
603979776
553649152
100664320
167773184
285213696

编辑:

要将各个二进制数字读入矩阵,您可以使用它(48 是“0”的 ASCII 代码):

cell2mat(textread('bin_MCS.txt','%s'))-48

关于file - Matlab:如何从文件中读取二进制数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18635739/

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