How to reduce the time?
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Laurens Bakker
on 7 Mar 2012
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
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!