Suggestion for rewrite of the for loop and while loop
Show older comments
Hi, i have created a code. However, it takes very long execution time to execute the code.Can anyone suggest a better solution to improve on the code?Here is the code.
%To receive received=fgetl(s); %Get from serial port using fgetl
file=[file received]; %The received bits is joined together to form a stream of bits.
%To form back the file
size_byte=fix(size(file)/32);
M=size_byte(2);
Video=[];
for j=1:M %For loop to get the binary bits back to matrices format
b=16*(j);
a=-15+b;
Video= [Video;file(a:b)];
end
dec=bin2dec(Video);
fid1=fopen (Save_file, 'wb');
count=fwrite(fid1, dec, 'uint16');
I have run using the profiler and it stated is the fgetl and Video= [Video;file(a:b)];which cause alot of execution time.Can anyone help to suggest for a better solution?I need it urgently. Thanks.
3 Comments
Jason Ross
on 25 Apr 2011
What is "a long execution time"
How much data are you dealing with?
Jason Ross
on 25 Apr 2011
Do you know how long you think it should take?
Do you have a performance limit you are required to meet?
MrPuzzled Marc
on 25 Apr 2011
Accepted Answer
More Answers (0)
Categories
Find more on Historical Contests 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!