Sorting vectors of structures, MATLAB in Engineering

Sorting Vectors of structures:

Whenever working with vector of structures, it is very common to sort based on a particular field within the structures. For illustration, recall the vector of structures used to the store information on various software packages.

16_Sorting Vectors of structures.png

Here is a function which sorts this vector of structures in ascending order depend on the price field.

Note that only the price field is compared in the sort algorithm, but the whole structure is replaced. That is therefore each element in the vector, that is a structure of information about a specific software package, that remains intact.


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

Related Discussions:- Sorting vectors of structures, Assignment Help, Ask Question on Sorting vectors of structures, Get Answer, Expert's Help, Sorting vectors of structures Discussions

Write discussion on Sorting vectors of structures
Your posts are moderated
Related Questions
Implementation of binary search: The binary search can be implemented as a recursive function. The recursive function below also implements this binary search algorithm. It re

Modular programs: In a modular program, the answer is broken down into modules, and each is executed as a function. The script is usually known as the main program. In orde

Function fieldnames - structure functions: The function fieldnames will return the names of the fields which are contained in the structure variable. >> pack_fields = fiel

Plotting from a Function: The following function creates a Figure Window as shown in figure, which shows various types of plots for similar y vector. The vector is passed as a

Vector operations: As vectors are special cases of matrices, the matrix operations elaborated (addition, subtraction, multiplication, scalar multiplication, transpose) work on

Illustration of Subfunctions: This is an illustration of running this program: >> rectarea Please enter the length: 6 Please enter the width: 3 For a rectan

Example to change the line width from the default: For illustration, to change the line width from the default of 0.5 to 1.5: >> set(hl,'LineWidth',1.5) As long as the

Expanding a function: The expand function will multiply out terms, and factor will do the opposite: >> expand((x+2)*(x-1)) ans = x^2 x-2 >> factor(ans)

Comparing strings: There are few functions which compare strings and return logical true when they are equivalent or logical false when not. The function strcmp compares the s