Illustration of indexing, MATLAB in Statistics

Illustration of Indexing:

Though, rather than of creating the index vector manually as shown here, the process to initialize the index vector is use to a sort function. The algorithm is as shown below:

  •  Initialize the values in index vector to be the indices 1,2, 3, ....
  •  Use any of the sort algorithm, but compare the elements in the original vector by using the index vector to index into it (example, using grades (grade_index(i))).
  •  Whenever the sort algorithm calls for replacing values, replace the elements in the index vector, not in the original vector.

The function which implements this algorithm is as shown below:

1481_Illustration of Indexing.png

For illustration, for the grades vector as given:

>> clear grade_index

>> grade_index = createind(grades)

grade_index =

2 5 1 6 4 3

>> grades(grade_index)

ans =

70 80 85 91 95 100

Posted Date: 10/22/2012 7:52:17 AM | Location : United States







Related Discussions:- Illustration of indexing, Assignment Help, Ask Question on Illustration of indexing, Get Answer, Expert's Help, Illustration of indexing Discussions

Write discussion on Illustration of indexing
Your posts are moderated
Related Questions
Vectors of nested structures: The Combining vectors and nested structures are possible to have a vector of structures in which several fields are structures themselves. Here i

Need of a nested loop: How would we sum each individual column, rather than getting an overall sum? Answer: The programming technique would need a nested loop in whi

Advanced File Input and Output: In that section, we saw how to read the values entered by user using the input as well as the output functions disp and fprintf, that shows inf

Example of Mode When no value appears more often than any other, the smallest value in the vector will be the mode of the vector. >> shortx = [2 5 1 4]; >> mode(shortx

Areacirc function: The areacirc function can be called from the Command Window as shown here, or from a script. Here is a script which will prompt the user for the radius of o

Illustration of Indexing into vectors of structures: For illustration, the function to print the information from packages has been modified therefore in addition to the vecto

Vectorizing: In most of the cases in MATLAB, loops are not essential. As MATLAB is written specifically to work with the vectors and matrices, most operations can be completed

Illustration of Binary search: An illustration to search for the key of 91 in the vector is as shown below: The table below shows what will happen in each iteration of

Function Stubs: The other common debugging method, which is used when there is a script main program which calls many functions, is to use the function stubs. A function stub

MENU Function: The MATLAB also has a built-in function known as menu which will display a figure Window with push buttons for the choices. The very first string passed to the