Help: matlab max return wrong value?

In summary, when using the max function in Matlab, it is important to specify the correct dimension when working with matrices or arrays and to ensure that the data is in the correct format. If there is an error in the code or data, it should be carefully reviewed and fixed. The max function only works on numeric data and can be used with indexing to find the maximum value in a specific range. NaN values are ignored by the max function, but can be included in the calculation by using the 'omitnan' option.
  • #1
yangf73
1
0
Hi,

I am using MATLAB max to find maximum along dimension 4. However I must made some mistake because the returned value is not the maximum sometimes:
ans =

142.1571
----------------
Can someone please help? Thanks.
 
Last edited:
Physics news on Phys.org
  • #2
please post the entire code, something we can try to replicate

are you using

max(A,[],4)

?
 
  • #3
Did you name a previous variable/function max?
 
  • #4
I often think that some new members here misread the title of this site as psychicsforums rather than physicsforums. How else can you explain posts like this one. :wink:
 
  • #5


Hi there,

Thank you for reaching out for help with your issue in MATLAB. It's difficult to determine the exact issue without seeing your code, but I can offer some suggestions that may help.

First, make sure that the input values you are using for the max function are in the correct format and that they are all numerical values. If there are any non-numerical values or missing data, it may affect the results.

You can also try using the "max" function with the additional input argument "omitnan" set to true. This will ignore any NaN (not a number) values in your data and may give you more accurate results.

If you are still having trouble, it may be helpful to check the values in your data and manually confirm the maximum value to compare it to the result from the max function. This can help you identify any discrepancies or errors in your code.

I hope this helps and good luck with your research!

Best,
 

1. Why does my Matlab max function return the wrong value?

There could be a few reasons for this. One possibility is that you are using the max function on a matrix or array and not specifying the correct dimension. Another possibility is that your data is not in the correct format for the max function to work properly. It's also possible that there is an error in your code or in the data itself.

2. How can I fix the incorrect max value returned by Matlab?

If you are using the max function on a matrix or array, make sure to specify the correct dimension. You can also try converting your data into the correct format for the max function to work properly. If there is an error in your code, carefully review and debug it to identify and fix the issue. You should also double check your data to ensure it is accurate.

3. Can I use the max function on non-numeric data in Matlab?

No, the max function in Matlab only works on numeric data. If you are trying to use it on non-numeric data, it will return an error. You may need to use a different function or method to find the maximum value in non-numeric data.

4. Is there a way to find the maximum value in a specific range of data using Matlab?

Yes, you can use the max function with indexing to find the maximum value in a specific range of data. For example, if you have a vector named 'data' and want to find the maximum value between indices 5 and 10, you can use the command max(data(5:10)). This will return the maximum value within that specific range.

5. How does the max function handle NaN (Not a Number) values in Matlab?

When using the max function in Matlab, NaN values will be ignored. This means that if your data contains NaN values, they will not be included in the calculation of the maximum value. If you want to include NaN values in the calculation, you can use the 'omitnan' option when calling the max function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
Back
Top