how to find the largest scalar in array with 2 ways?
Show older comments
I have matrix how to find the largest scalar
1 Comment
Jan
on 31 Aug 2017
What does "2 ways" mean? Do not assume, that we can read your mind.
Accepted Answer
More Answers (1)
Jan
on 31 Aug 2017
"Largest scalar". Sounds like a maximum. Then take a look into the documentation.
docsearch maximum
The first hits sound strange: "movmax", "cummax", "namelengthmax". Not really useful. But hope, that MathWorks was smart. Open the first link, scroll down and look into the "See also" line. You find similar commands there. And here you get "max". Click on the command to open the docs, or type this directly (guessing this name is not too difficult):
doc max
The output of this command would be fine for a vector, but you have a matrix. Then the maximum for each column is replied.
Read the "Getting Started" chapters again - how to convert a matrix into a vector. Please do this - it will be very useful. You cannot ask the forum for all basics. You will find A(:).
You want a 2nd way? Try a loop: Use a for loop to step through all elements of A. Start with the value v = -Inf. If the current element is larger, store it in v. At the end v will contain the maximum.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!