How to make the conversion more faster?
Ältere Kommentare anzeigen
Hi. I am trying to convert from decimal to Canonic Signed Digit(CSD). I took the code from this link: http://www.mathworks.com/matlabcentral/fileexchange/9730-canonical-signed-digits
This code takes the decimal input and provides CSD output in string form.
Now i am trying to apply this code for a matrix and took the idea from this link:
Following is the code:
C = [2.336 -1.900; 3.541 -0.219];
range = 5;
resolution = 15;
k = 1;
CC = repmat('', numel(C), range+resolution);
for i = 1 : numel(C)
CC(k,1:(range + resolution )) = csdigit(C(i),range,resolution);
k = k+1;
end
This code used many times by some other codes and the input matrix "C" may have thousands elements. So, if it is possible to reduce the time, it will help my research a lot.
4 Kommentare
Oleg Komarov
am 11 Mär. 2012
Your example code doesn't work.
After fixing it, almost 90% of the time is taken away by csdigit.
I recommend to recode that function.
Shifat
am 11 Mär. 2012
Jan
am 11 Mär. 2012
Please, Shifat, post some working code.
Shifat
am 11 Mär. 2012
Akzeptierte Antwort
Weitere Antworten (2)
Daniel Shub
am 11 Mär. 2012
0 Stimmen
The easiest thing is probably to use a faster computer.
A quick look at csdigit doesn't reveal anything to me that is obviously multi-threaded. You could try replacing your for loop with a parfor loop. This could give you a speed up proportional to the number of cores. If you have access to a cluster, you can even get a bigger boost.
You could also strip all the error checks, and anything else that you do not need, from csdigit. It is probably not a big boost, but it may help.
You could convert csdigit to a mex and see if that buys you anything.
1 Kommentar
Shifat
am 11 Mär. 2012
Shifat
am 12 Mär. 2012
Kategorien
Mehr zu Numeric Types finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!