How do I store all 'ans' values in a single matrix?
1 view (last 30 days)
Show older comments
Kayle San Juan
on 16 Dec 2015
Answered: Walter Roberson
on 16 Dec 2015
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 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!