Write a MATLAB code to find the maximum value in a given array and its corresponding index.

1 Answers
Answered by suresh

How to find the maximum value in a MATLAB array with its index

How to find the maximum value in a MATLAB array with its index

To find the maximum value in a given array and its corresponding index in MATLAB, you can use the following code:


array = [3, 7, 2, 9, 5];
[maxValue, index] = max(array);
fprintf('The maximum value is %d at index %d', maxValue, index);

This code initializes an array with values, then uses the 'max' function to find the maximum value and its index in the array. Finally, it prints the result using 'fprintf'.

By running this MATLAB code, you will be able to determine the maximum value in the array and its corresponding index.

Answer for Question: Write a MATLAB code to find the maximum value in a given array and its corresponding index.