Code covered by the BSD License  

Highlights from
Max or Min position in a matrix

2.0

2.0 | 1 rating Rate this file 8 Downloads (last 30 days) File Size: 1.45 KB File ID: #26890

Max or Min position in a matrix

by Damilola Ogunbiyi

 

09 Mar 2010

Used to obtain the particular position where a maximum or minimum occurs in a matrix.

| Watch this File

File Information
Description

Provide a matrix of which you would like to obtain the position where its maximum or minimum occurs. By specifying your desire for the max or min position, simply run the program to obtain it.

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
09 Mar 2010 John D'Errico

This has SOME good features. What do I like about it? It does have help, to some extent. But the help could be a bit better. Here is what you get when you use help on this function:

>> help findit
  To obtain the position of either the maximum or minimum element in a vector
 
  INMAT specifies the input matrix
  Use OPT specify your choice of obtaining a maximum or minimum
  Set OPT=1 when trying to obtain the maximum
  Set OPT=2 when trying to obtain the minimum
 
 
  Oluwadamilola (Damie) Martins Ogunbiyi
  University of Maryland College Park
  Department of Electrical and Computer Engineering
  Communications and Signal Processing
  08-March-2010
  Copyright 2009-2010 Black Ace of Diamonds.

See that there is an H1 line in the help block. I like that. There is a simple description of the arguments. But what order do they go in? I might guess that INMAT is the first argument, because it is mentioned first. But there is no other hint.

Next, does this require that OPT be supplied? Is OPT and optional argument? If so, then it should have a default, and the help should tell us what is the default. As it turns out, there is no default value for opt.

I do like that there is a check for opt being a valid argument.

A good thing to do when you write help is to give an example of use. Show what SHOULD happen when you call your function on some simple test array, like magic(3).

Another good thing to put in your help is a see also line.

It does seem silly to me that when you type help for this code, it gives you more information about the author than it does about the function itself.

How about the code itself? Sadly, this part is TERRIBLE. Why in the name of god and little green apples did the author use nested loops to do this?

See that min and max would have given all the information the author needed, with a final call to ind2sub to get the actual subscripts of the result. Worse, the author actually calls min or max before the loop itself!!!!!!!!

My rating for this would have been about 3.5 stars before I got into the coding style itself. But solving the problem with nested loops is a ridiculous silly choice.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
find Damilola Ogunbiyi 09 Mar 2010 11:01:28
findit Damilola Ogunbiyi 09 Mar 2010 11:01:28
max Damilola Ogunbiyi 09 Mar 2010 11:01:28
min Damilola Ogunbiyi 09 Mar 2010 11:01:28
matrix Damilola Ogunbiyi 09 Mar 2010 11:01:28

Contact us at files@mathworks.com