Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:22:25+00:00 2026-06-16T22:22:25+00:00

I would like to compute the maximum and, more importantly, its coordinates of an

  • 0

I would like to compute the maximum and, more importantly, its coordinates of an N-by-N…by-N array, without specifying its dimensions.

For example, let’s take:

A = [2 3];
B = [2 3; 3 4];

The function (lets call it MAXI) should return the following values for matrix A:

[fmax, coor] = MAXI(A)

fmax =
   3

coor =
   2

and for matrix B:

[fmax, coor] = MAXI(B)

fmax =
    4

coor=
    2   2

The main problem is not to develop a code that works for one class in particular, but to develop a code that as quickly as possible works for any input (with higher dimensions).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:22:26+00:00Added an answer on June 16, 2026 at 10:22 pm

    To find the absolute maximum, you’ll have to convert your input matrix into a column vector first and find the linear index of the greatest element, and then convert it to the coordinates with ind2sub. This can be a little bit tricky though, because ind2sub requires specifying a known number of output variables. For that purpose we can employ cell arrays and comma-separated lists, like so:

    [fmax, coor] = max(A(:));
    if ismatrix(A)
        C = cell(1:ndims(A));
        [C{:}] = ind2sub(size(A), coor);
        coor = cell2mat(C);
    end
    

    EDIT: I’ve added an additional if statement that checks if the input is a matrix or a vector, and in case of the latter it returns the linear index itself as is.

    In a function, it looks like so:

    function [fmax, coor] = maxi(x)
        [fmax, coor] = max(A(:));
        if ismatrix(A)
            C = cell(1:ndims(A));
            [C{:}] = ind2sub(size(A), coor);
            coor = cell2mat(C);
        end
    

    Example

    A = [2 3; 3 4];
    [fmax, coor] = maxi(A)
    
    fmax =
        4
    
    coor =
        2    2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to compute the maximum of translated images along the direction of
I have data that I would like to compute some statistics with. The data
For given floating point numbers x and a , I would like to compute
I would like to know how to create a computed observable array. In my
I have a List, and I would like to compute a double[360] containing the
I would like to compute the identity of tabs in the chrome browser in
I would like to compute both the sine and co-sine of a value together
I have two collections a and b . I would like to compute the
I would like to compute time that spans between two particular moments: - start
I would like to compute the absolute difference of two integers. Naively, this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.