How to store values from toc into an array

help with bonus question

댓글 수: 1

i need help with question 5 and the bonus depicted in the screenshot/attachment

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 7일

3 개 추천

tic;
for K = 1 : 10
times(K) = toc;
end

댓글 수: 6

%HW3.m
im trying to do question 5 of my homework but it isn't working. the homework question is provided in link/attachment
counter=0;
for n=[1E1 1E2 1E3 1E4 1E5]
timeslow=zeros(1,5)
tic;p=prime_list_slow_class(n);timeslow=toc
counter=counter+1;
end
counter=1;
for n=[1E1 1E2 1E3 1E4 1E5]
timeslist=zeros(1,5);
tic;p=prime_list(n);timeslist =toc
counter=counter+1;
end
counter=2;
for n=[1E1 1E2 1E3 1E4 1E5]
timesieve=zeros(1,5);
tic;p=prime_sieve(n);timesieve=toc
counter=counter+1;
end
figure(3);
hold on;
loglog(timeslow,[1E1 1E2 1E3 1E4 1E5],'b-','linewidth',3); hold on
loglog(timeslist,[1E1 1E2 1E3 1E4 1E5],'r-','linewidth',3); hold on
loglog(timesieve,[1E1 1E2 1E3 1E4 1E5],'g-','linewidth',3); hold on
You are overwriting all of timeslow, timeslist, timesieve each iteration of the loop.
for N = 1 : 5
n = 10^N;
...
timeslow(n) = toc;
...
end
still not plotting,nor working. thanks though.
Only initialize timeslow to zero before the for loop, not in the for loop.
thanks, how do i do the bonus ?
Walter Roberson
Walter Roberson 2018년 2월 7일
편집: Walter Roberson 2018년 2월 7일
You write a function named prime_count that takes n as an input and returns a vector named Upsilon which is of length n, each element of which is the number of prime numbers less than or equal to its index. The function prime_count must call prime_sieve exactly once -- however, it is not required that your function use the results returned by prime_sieve .

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2018년 2월 7일

편집:

2018년 2월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by