Find Max P04 in MATLAB for i, j, and k values using 8x89x89 matrix

Click For Summary
SUMMARY

The discussion focuses on finding the maximum value of P04 in MATLAB for an 8x89x89 matrix generated by the Mach3 function. The user attempts to retrieve the maximum P04 values for varying indices i, j, and k using nested for loops. The correct approach involves passing the entire P04 matrix to the max function, rather than individual elements. The solution is to use [c(i), I] = max(P04) to obtain the maximum values and their corresponding indices.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of matrix operations in MATLAB
  • Knowledge of the Mach3 function and its parameters
  • Basic concepts of for loops and indexing in MATLAB
NEXT STEPS
  • Study MATLAB matrix manipulation techniques
  • Learn about the Mach3 function and its applications
  • Explore MATLAB's max function and its usage with multi-dimensional arrays
  • Investigate optimization techniques for nested loops in MATLAB
USEFUL FOR

MATLAB programmers, engineers working with matrix computations, and anyone interested in optimizing performance in numerical simulations.

ADunn
Messages
6
Reaction score
0
In MATLAB I have a function which calculates P04 for different values of i,j, and k providing a 8x89x89 matrix of values. I am trying to find the max P04 for each value of i and the corresponding j and k values.

Here are my for loops:

for i = 1:1:8;
M1(i) = 2+0.1*i;
for j = 1:1:89;
betaA(j) = j*pi/180;

for k = 1:1:89;
betaB(k) = k*pi/180;

[P04(i,j,k)] = Mach3(M1(i),betaA(j), betaB(k),P01);

end
end

[c(i),I] = max(P04(i,j,k));

end
I tried:

[c(i),I] = max(P04(i,j,k)); (as above)

and

[val(i),ind]= max(P04(i,j,k));

both gave me a max value of zero and did not give me the indices.

Thanks for any help!
 
Last edited:
Physics news on Phys.org
ADunn said:
[c(i),I] = max(P04(i,j,k));
P04(i,j,k) is a single element of an array. The entire array must be passed to the max function
[c(i),I] = max(P04);
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 41 ·
2
Replies
41
Views
10K
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
0
Views
2K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 4 ·
Replies
4
Views
7K