Replacing a for loop with a time efficient alternative ?
2 views (last 30 days)
Show older comments
So I am making my own algorithm to implement binary huffman encoding for grayscale images, my code works very well but the encoding process for loop takes too much time if the image has many levels, it goes like this:
(The S stands for symbols and the Levels is the input image reshaped into a vector, dict is my formed codeword dictionary which is similar to using huffmandict)
%Encoding the stream:
Encoded_Stream = [];
Decoding_Cell = {};
for i=1:length(Levels)
for j=1 : length(S)
if Levels(i) == dict{j,1}
Encoded_Stream = [Encoded_Stream dict{j,2}];
Decoding_Cell{i,1} = dict{j,2};
end
end
end
Is there any faster solution to find the corresponding codeword in the dictionary without using this second for loop
9 Comments
Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!