calculating the time

조회 수: 11 (최근 30일)
kash
kash 2012년 5월 22일
I have a code which runs for 10 iterations in this i want to calculate the time for each iteration and find the minimum time for iteration,please help

채택된 답변

Wayne King
Wayne King 2012년 5월 22일
You can use tic and toc.
t = zeros(1,100);
for n = 1:100
A = rand(n,n);
b = rand(n,1);
tic
x = A\b;
t(n) = toc;
end
[mintime,I] = min(t);
  댓글 수: 2
kash
kash 2012년 5월 22일
Thanks Wayne I have a code for compression ratio
function [CR PSNR]=cpdp(I)
input_image=I;
n=3;
%*****************************************************************************
[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('haar');
%wavedec2 - Multi-level 2-D wavelet decomposition.
[c,s]=wavedec2(input_image,n,Lo_D,Hi_D);
disp(' the decomposition vector Output is');
disp(c);
%*************************************************************************************
[thr,nkeep] = wdcbm2(c,s,1.5,3*prod(s(1,:)));
[compressed_image,TREED,comp_ratio,PERFL2] =WPDENCMP(thr,'s',n,'haar','threshold',5,1);
re_ima1 = waverec2(c,s,'haar');
re_ima=uint8(re_ima1);
CR=comp_ratio;
Er1= mean2((single(I) - single(re_ima)).^2);
PSNR = 20 * log10 (255 / sqrt(Er1));
I wrote this as a function program where i have 10 images inside for loop i have called this function,now i want to calculate which image has highest CR,plese help
Jan
Jan 2012년 5월 22일
@Wayne: In my opinion your program solves the question sufficiently. +1

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Wayne King
Wayne King 2012년 5월 22일
Just save the CR values in a vector, then query which one is the max
  댓글 수: 3
kash
kash 2012년 5월 22일
ALSO HOW TO DISPLAY THE IMAGE WHICH HAS HIGHEST CR
Jan
Jan 2012년 5월 22일
Dear kash, there is no reason for shouting.
"but not getting the result" is vague. I guess you get a detailed error message instead, because you try to assign the array CR to one of its elements. This is not possible for obvious reasons.
But the questions about the compression ratio do not concern the original question, such that it it recommended to open a new thread. Otherwise it gets impossible to accept the best answer.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by