Replacing a for loop with a time efficient alternative ?

1 view (last 30 days)
Mahmoud Emad
Mahmoud Emad on 8 Apr 2020
Commented: Mehmed Saad on 9 Apr 2020
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};
Is there any faster solution to find the corresponding codeword in the dictionary without using this second for loop

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!