フィルターのクリア

How do I store all 'ans' values in a single matrix?

1 回表示 (過去 30 日間)
Kayle San Juan
Kayle San Juan 2015 年 12 月 16 日
回答済み: Walter Roberson 2015 年 12 月 16 日
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!

採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 16 日
result = [dec2b(x), dec2b(x)];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by