How to reduce the time?
古いコメントを表示
Hi. I am trying to convert a decimal matrix in to binary form by using following code:
k = 1;
P = ''; %%P is the output matrix
for i = 1 : numel(s) %%s is the input matrix
P(k,1:bin_total) = bin(fi(s(i),1,8,6));
%%Decimal to binary conversion
k = k+1;
end
I am trying to reduce the time because the input matrix may have 1000 elements. So it's taking very long time for converting in to binary.
Can anyone please give me any idea how to make the code more faster?
Thanks.
7 件のコメント
Walter Roberson
2012 年 3 月 1 日
Is there a requirement to use the fixed point toolbox?
What kind of inputs are in s() ?
8,6 ... you are wanting binary equivalent of fractions?
Shifat
2012 年 3 月 1 日
Jan
2012 年 3 月 7 日
Double post, see http://www.mathworks.com/matlabcentral/answers/31130-how-to-reduce-the-time
Walter Roberson
2012 年 3 月 7 日
"I find it easiest" is not really an answer to "Is there a requirement to use the fixed point toolbox?"
I do not have the fixed-point toolbox, so I would be unable to test or time solutions based on the fixed-point toolbox. If you *must* use the fixed-point toolbox, I do not have the resources to assist in this matter. If you just _prefer_ the fixed point toolbox then I may be able to come up with something.
Shifat
2012 年 3 月 7 日
Walter Roberson
2012 年 3 月 7 日
Okay -- signed or unsigned?
Shifat
2012 年 3 月 7 日
回答 (2 件)
Laurens Bakker
2012 年 3 月 7 日
Hi Shifat,
the base MATLAB distribution has a function for this:
P = dec2bin( fix(s) );
where fix() cuts off the fractional part. Let me know if this is not fast enough for you. There are some faster ways of doing it, but that gets somewhat involved.
Cheers,
Laurens
Shifat
2012 年 3 月 10 日
1 件のコメント
Oleg Komarov
2012 年 3 月 11 日
Do not delete posts that have been answered.
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!