我似乎很难在 MATLAB 中累积然后输出一个变量。请看下面的代码。我要做的就是将十进制表示添加到总数中。我已经尝试过感觉像是一百万种东西。我想我误解了如何遍历 MATLAB 向量。看起来很简单。
%clear the command window
clc();
%clear all of the variable stored
clear all;
% close all plots and figures
close();
num = 1.32421875000000000000;
format long g;
%bin_num = dec2bin(num);
fprintf("binary representation of num: %.45f \n", num);
num = num + (1/2^52);
fprintf("the next largest number is: %.45f \n", num);
num = num - (1/2^52);
%bin = '0011111111110101001011111111111111111111111111111111111111111111'
sign = '0';
exponent = '0 1 1 1 1 1 1 1 1 1 1';
decexponent = bin2dec(exponent);
mantissa = [0 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
for i = 1:1:length(mantissa)
sumtotal = sumtotal + mantissa(i)*(1/(2^i)));
end
%num = (-1)^bin2dec(sign)*(2^(decexponent-1023))*(1 + sum);
fprintf("the next smallest number is: %.45f \n", (sumtotal));