Code covered by the BSD License

### Highlights from Find the "I J K" indices of any element number "e" in the 2D or 3D matrix

1.5

1.5 | 3 ratings Rate this file 9 Downloads (last 30 days) File Size: 1.84 KB File ID: #34824

# Find the "I J K" indices of any element number "e" in the 2D or 3D matrix

28 Jan 2012 (Updated )

Many a times it may be required to identify the indices, 'i','j' and 'k' values of an element number

File Information
Description

Many a times it may be required to identify the indices, 'i'(row),'j'(column) and 'k'(plane) values of an element number 'e'

% SAMPLE USAGE 1
% [row,column,plane]=findijk(79,[10 10 10])
% row =
% 9
% column =
% 8
% plane =
% 1
% SAMPLE USAGE 2
% [row,column,plane]=findijk(79,[10 10])
% row =
% 9
% column =
% 8
% plane =
% 1
% SAMPLE USAGE 3
% [row,column,plane]=findijk(301,[10 10 10])
% row =
% 1
% column =
% 1
% plane =
% 4

[NOTE: Its just another method and users who are inquisitive enough to know a different approach (as with the inbuilt function ind2sub) to do the same job, would find this interesting.]

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
23 Feb 2012

Ok, the code is formatted a bit better now, but it would be even better if you also formatted the help a bit better too. For example, the first line after the function definition should be a one line description of what the function does. This is known as the h1 line and is displayed when you use the 'lookfor' function to search for a function. Following this should be your help text. There should be no break in the text so that is is all displayed when you type 'help findijk' at the command prompt. You should also move all the comments at the end of the file to the help text at the top instead so it is also displayed in this case. Finally, at the bottom of your help you should add the line:

To make users aware of these functions.

14 Feb 2012

I have updated the file accordingly, in terms of the formatting and layout:). I agree the inbuilt function is better. Users inquisitive enough to know about another approach to the same job may find this interesting. The updated file should appear online soon...

14 Feb 2012

Thank you for your comment and the rating :)

14 Feb 2012

Actually I see it's not your first post, and your others seem reasonable, so I'm not sure what made you think this one was a good idea. For this reason, one star.

14 Feb 2012

ok, but your code is also terrible, badly formatted, confusing, and badly laid out. If it is intended to help anyone looking on the file exchange, it is pretty much as bad as it can be for this purpose. At worst, it might have hidden the existence of ind2sub from some new user.

Perhaps consider not posting anything further until it either does a task not already available in matlab or by some other file on the file exchange, or is a good example of matlab coding that might educate someone. I refrained from giving you one star as this is clearly your first post, next time I'd be forced to be honest. Also consider removing this file, as it adds nothing to the exchange.

Sorry if I am being too blunt.

13 Feb 2012

Dear RichardCrozier and John D'Errico,,, thank you for our comments and rating.

Actually, I was not aware of a function like sub2ind when i needed it. So, had to write my own code.

Since i have followed a different approach for getting the same answer, i wanted to share it with the community.

Yeah true, the inbuilt matlab code is more complete. I will think of generalizing my code too and will repost it someday. Thanks :)

10 Feb 2012

Why use this when the functionality already exists in matlab, and has existed for many years? And of course, ind2sub is more complete than this code is too.

10 Feb 2012

Or you could use matlab built-in function ind2sub, e.g.

[row,col,plane] = ind2sub(rcp,e)

e.g.

>> [row,col,plane] = ind2sub([10 10 10],79)

row =

9

col =

8

plane =

1