How do I store all 'ans' values in a single matrix?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kayle San Juan
am 16 Dez. 2015
Beantwortet: Walter Roberson
am 16 Dez. 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 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!