clc; clear; a = textread('E:/output.txt','%s'); % 输入txt文件 m = N; % N bits n = length(a); % 需要转换的数字个数 Qin0 = zeros(n,1); for i=1:n Qin0(i) = bin2dec( a{i} ); %将所有二进制数转换为无符号位十进制数 if(Qin0(i) > 2^(N-1)-1) % 如果结果大于2^(N-1)-1 Qin0(i)=bin2dec(a{i})-2^m; % 转换为负数 end end
标签:end,二进制,bin2dec,Qin0,matlab,txt From: https://www.cnblogs.com/lao3er/p/16718519.html