필터 지우기
필터 지우기

Storing Maximum Value & corresponding variable in iterative process.

조회 수: 1 (최근 30일)
Shantanu K
Shantanu K 2013년 3월 21일
max1 = [-inf 0 0 0];
for p=1:3
for q=1:6
for z=1:100
if p+q<6;
a=2*p;
b=5*q;
k=z*z;
x=k*4+1;
k1 = a*x+b*k+1;
if k1 > 4,
max(1,z) = k1;
max(2,z) = p;
max(3,z) = q;
max(4,z) = z; end
else
end
end
end
end
Here there are total three loops used for p,q,z. I want to store value pf k1 which is more than 4 & corresponding p,q,z. i am facing problem that while loop is executed values of variable max are getting replaced in every loop. I have to gather data having k1>4 and correponding p,q,z

답변 (1개)

Jan
Jan 2013년 3월 21일
The minimal possible value of k1 is 16, when I set the minimal values for p, q, z in the formula k1 = a*x+b*k+1. Therefore you can omit the check for > 4. And all possible combinations with p+q<6 are wanted as result? This could be achieve much easier.
The indentation of your code is confusing due to the "end" which is append behinde the line.
You pre-allocate the variable max1, but in the code max is assigned, but it leads to problems frequently, when built-in functions are shadowed.
  댓글 수: 1
Shantanu K
Shantanu K 2013년 3월 21일
okay...max1 is mistake of mine.....then how to proceed. This is not actual problem....i have made replication to make it simple. Logic which i will get here will be implemented in main program......in that program its not so easy to tell about minimum value......so how to proceed then?

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by