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

In summary, the individual values of P04 for different values of i,j, and k are calculated using a MATLAB function. The speaker is trying to find the maximum P04 for each value of i, and the corresponding j and k values. They have tried using for loops and the max function, but have encountered issues with getting the correct indices.
  • #1
ADunn
6
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
  • #2
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);
 

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

How do I find the maximum value of P04 in MATLAB?

To find the maximum value of P04 in MATLAB, you can use the max function. This function takes in an array or matrix and returns the maximum value. For example, if your matrix is named M, you can use max(M) to find the maximum value.

Can I specify specific i, j, and k values to find the maximum P04 in a matrix?

Yes, you can use the max function with additional parameters to specify specific i, j, and k values. For example, if you want to find the maximum value of P04 in a specific row and column, you can use max(M(row, column)).

How do I find the maximum P04 in a large matrix in MATLAB?

If your matrix is very large, you can use the max function with the [], 'all' syntax to find the maximum value in the entire matrix. This will return a single value that is the maximum of the entire matrix. For example, max(M, [], 'all') will return the maximum value of the matrix M.

Is there a way to find the index of the maximum P04 value in a matrix in MATLAB?

Yes, you can use the max function with an additional output argument to find the index of the maximum value. For example, if you use [max_value, max_index] = max(M), the variable max_index will contain the index of the maximum value in the matrix M.

Can I use the max function to find the maximum P04 value in a specific portion of a matrix in MATLAB?

Yes, you can specify a range of values within a matrix to find the maximum value using the max function. For example, if you want to find the maximum value in a specific sub-matrix of M, you can use max(M(start_row:end_row, start_column:end_column)). This will return the maximum value within that specified range.

Similar threads

Back
Top