how do i plot number of iteration verses accuracy
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to plot following two complexity comparision graph
1) How do I plot time vs number of iteration in matlab. Since one loop take 55 sec while another loop takes 200 sec.
2) Number of iteration vs accuracy(10^-5 to 0.1)
댓글 수: 8
Jan
2019년 5월 17일
What does "if this is the case" mean? You post the screenshot of a plot. This does not explain, what you want to plot. Without seeing your code, we cannot guess how you can collect the numbers. But actually it works like this:
x = zeros(1, 100); % Pre-allocation
for k = 1:100
x(k) = sin(1 / k); % Insert your calculation here
end
답변 (1개)
Bjorn Gustavsson
2019년 5월 16일
Something like this should be doable:
i_iterations_to_try = [10:5:200].^2; % Some array with number of iterations to run through
for i1 = 1:numel(i_iterations)
accuracy(i1) = your_optimizationfunction_whatever(i_iterations_to_try(i1),other,input);
end
semilogx(accuracy,i_iterations_to_try,'d--')
HTH
댓글 수: 5
Jan
2019년 5월 17일
@Manoj Kumar: Bjorn gave you an example of how to collect data. Because you did not tell us any details about your code, he had to invent an example. So it is not meaningful if you ask for explanations of this example, e.g. why he as square the data. He could set it to the power or sqrt(17) also, because they are arbitrary inputs, which must replaced by your values in the real code. E.g.:
M = 1
x = zeros(100, 10); % Pre-allocation for speed
y = zeros(100, 10); % Pre-allocation for speed
for r = 1:10
for k = 1: 100
[x(k, r), y(k, r)] = my_function(a(:, :, k), N(r), M);
end
end
Collecting the values works by using an index and storing them in an array.
Bjorn Gustavsson
2019년 5월 17일
Manoj: Oh, your function wasn't named "your_optimizationfunction_whatever"? When you complained about my arbitrary selection of number of iterations to try and not the function-name I thought that I had made a very lucky guess of your function-name!
Read that as: How could I or anyone else give you your selected number of iterations or any other details like function-name or the input arguments to your function when you haven't given us any information about any of those details? When trying to use the replies try to think about how the reply leads _towards_ your goal, and what you might have to change or expand to reach your goal, also consider the amount of information the responders have to work from when doing this.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!