how to get answer from tic tok command that stays on the screen

3 views (last 30 days)
Hi, I m using tic toc commamand , but answer appears in commad window for nano sec, i think and then disappears. i have attached the code. can some one tell me where is the mistake?I cannot record the values.
function .....
.....
tic
for i=0:total_Blocks-1
Plain_Text=linear_Image((i*16)+1:(i*16)+16);
Cipher_Text = cipher (Plain_Text, w, s_box, poly_mat, 1);
re_plainText = inv_cipher (Cipher_Text, w, inv_s_box, inv_poly_mat, 1);
enImage((i*16)+1:(i*16)+16)=Cipher_Text;
deImage((i*16)+1:(i*16)+16)=re_plainText;%Retrieved Plain Text
toc
end
figure,
imshow(uint8(enImage));
end

Accepted Answer

per isakson
per isakson on 12 Apr 2020
Edited: per isakson on 12 Apr 2020
Replace
toc
by
elapsed_time = toc;
which saves the elapsed time iin the variable, elapsed_time. And add
elapsed_time
after imshow()
In response to comment
The first mistake is that tic is outside the for-loop and toc inside. I missed that because toc wasn't intended. That raises the question which elapsed time do you want to measure.
Try something like this
function elapsed_time = xyz( )
% code
elapsed_time = nan( total_Blocks, 1 );
for ii=0:total_Blocks-1
tic
Plain_Text=linear_Image((ii*16)+1:(ii*16)+16);
Cipher_Text = cipher (Plain_Text, w, s_box, poly_mat, 1);
re_plainText = inv_cipher(Cipher_Text, w, inv_s_box, inv_poly_mat, 1);
enImage((ii*16)+1:(ii*16)+16)=Cipher_Text;
deImage((ii*16)+1:(ii*16)+16)=re_plainText;%Retrieved Plain Text
elapsed_time(ii+1) = toc;
end
figure,
imshow(uint8(enImage));
end
  6 Comments
per isakson
per isakson on 13 Apr 2020
Edited: per isakson on 13 Apr 2020
"nothing works" is not a very useful response. What exactly doesn't work?
"[I] have tried ur function as well" How did you call my function? The output variable, elapsed_time, was it empty on return?
lilly lord
lilly lord on 17 Apr 2020
sorry i m new in coding , later i work on ur ur comment /answer
"The first mistake is that tic is outside the for-loop and toc inside. I missed that because toc wasn't intended. That raises the question which elapsed time do you want to measure.'
and i have solved the problem. thank you so much for ur help.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!