How do I store all 'ans' values in a single matrix?
조회 수: 1 (최근 30일)
이전 댓글 표시
Good day! I've been trying to create a decimal to binary converter for a project, but what I've wanted to do is to store all the answers generated by my codes in a single matrix, so that I can call this matrix for future references.
Here are my codes:
function [y1] = dec2b (x)
prompt = 'Input number: ';
x=input(prompt);
a = fracbin(x);
b = dec2bin (x,7);
y1 = strcat('1',b,a);
end
function binA = fracbin(x)
format long;
y = '';
[j,k] = size(x);
for i = 1:j*k
dec1 = dec2bin(x(i));
dec2 = bin2dec(dec1);
x(i) = x(i) - dec2;
for n = 1:24
if x(i)-(1/(2^n)) >= 0
y = strcat(y , '1');
x(i)=x(i)-(1/(2^n));
else
y = strcat(y, '0');
x(i) = x(i);
end
end
sprintf('%/n');
end
binA = y;
end
What I can't solve is this:
For example, I inputted number 35.6 when prompted, it would produce an ans output of 10100011100110011001100110011001
When I run the program again, and inputted number 32.4, the program would yield an ans value of 10100000011001100110011001100110
I want these data to be stored in a matrix, like so:
[10100011100110011001100110011001 10100000011001100110011001100110]
Please help me! I can't seem to figure this out. Have a nice day!
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!