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 7 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

by

 

28 Jan 2012 (Updated )

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

| Watch this File

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)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
23 Feb 2012 Richard Crozier

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:

% See also IND2SUB, SUB2IND

To make users aware of these functions.

14 Feb 2012 sunil anandatheertha

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 sunil anandatheertha

Thank you for your comment and the rating :)

14 Feb 2012 Richard Crozier

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 Richard Crozier

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 sunil anandatheertha

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 John D'Errico

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 Richard Crozier

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

Updates
04 Feb 2012

included a small change in the title and included an errata in the description.

14 Feb 2012

In accordance with the comment on this file, i have included adequate changes in the code as regards to the code formatting and layout. Also included a NOTE in the code description.

Contact us