how to find the largest scalar in array with 2 ways?
Mostrar comentarios más antiguos
I have matrix how to find the largest scalar
1 comentario
Jan
el 31 de Ag. de 2017
What does "2 ways" mean? Do not assume, that we can read your mind.
Respuesta aceptada
Más respuestas (1)
Jan
el 31 de Ag. de 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.
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!