Storing Maximum Value & corresponding variable in iterative process.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Jan
am 21 Mär. 2013
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.
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!