Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Questions about the elapsed time of Enumeration

조회 수: 1 (최근 30일)
Zoe Lin
Zoe Lin 2018년 5월 28일
마감: Zoe Lin 2018년 5월 29일
Hi,Everyone:
Today I want to show all possible result of 4 variables ,all of theirs range are from 1:0.1:10, 1 1 1 1 → 1 1 1 1.1 → 1 1 1 1.2 ... to 10 10 10 10.
I run my code,it has runs more than 17 hours,is it a acceptable phenomenon?
My code is following:
tic;
final=10;
Range=[1:0.1:final];
Total = length(Range)^4
weight=zeros(1,4);
cont=0;
for weight1=Range
for weight2=Range
for weight3=Range
for weight4=Range
if abs(weight1-0) > 1e-8
cont=cont+1;
weight(cont,:)=[weight1 weight2 weight3 weight4];
end
end
end
end
toc;
If my code should be adjusted, improved, please tell me your opinions,let's discuss.
Thanks for first !!

답변 (1개)

Paridhi Yadav
Paridhi Yadav 2018년 5월 28일
Hey in your code you are adding a row in weight every time the loop runs, instead of this while initializing weight give total number of rows like this weight = zeros(Total,4).
tic;
final=10;
Range=[1:0.1:final];
Total = length(Range)^4
weight=zeros(Total,4);
cont=0;
for weight1=Range
for weight2=Range
for weight3=Range
for weight4=Range
if abs(weight1-0) > 1e-8
cont=cont+1;
weight(cont,:)=[weight1 weight2 weight3 weight4];
end
end
end
end
end
toc;
  댓글 수: 1
Zoe Lin
Zoe Lin 2018년 5월 28일
Dear Paridhi Yadav:
It still work,finally, weight matrix will be (Total,4), too.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by