Illustration of vectors of structures, MATLAB in Engineering

Assignment Help:

Illustration of Vectors of structures:

In this illustration, the packages are vector which has three elements. It is shown as a column vector. Each and every element is a structure consisting of four fields, item_no, price, cost, and code. It may look like a matrix with rows and columns, but it is rather a vector of structures.

This can be generated in several ways. The one method is to generate a structure variable, as shown, to store the information on one software package. This can then be extended to be the vector of structures.

>> packages = struct('item_no',123,'cost',19.99,.  .  .

'price',39.95,'code','g');

>> packages(2) = struct('item_no',456,'cost', 5.99,.  .  .

'price',49.99,'code','l');

>> packages(3) = struct('item_no',587,'cost',11.11,.  .  .

'price',33.33,'code','w');

The first assignment statement shown generates the first structure in the structure vector; the next one generates the second structure, and so on. This really generates a 1 × 3 row vector.

Alternatively, the first structure could be considered as a vector to start with, taking illustration,

 

>> packages(1) = struct('item_no',123,'cost',19.99,.  .  .

'price',39.95,'code','g');

>> packages(2) = struct('item_no',456,'cost', 5.99,.  .  .

'price',49.99,'code','l');

>> packages(3) = struct('item_no',587,'cost',11.11,.  .  .

'price',33.33,'code','w');

 

Both of these techniques, though, include extending the vector. As we know that, preallocating any vector in MATLAB is more efficient than extending it. There are various techniques of preallocating the vector. By beginning with last element, the MATLAB would generate a vector with many elements. Then, the elements from 1 throughout end-1 could be initialized. For illustration, for a vector of structures which has three elements, begin with the third element.

>> packages(3) = struct('item_no',587,'cost',11.11,.  .  .

'price',33.33,'code','w');

>> packages(1) = struct('item_no',123,'cost',19.99,.  .  .

'price',39.95,'code','g');

>> packages(2) = struct('item_no',456,'cost', 5.99,.  .  .

'price',49.99,'code','l');


Related Discussions:- Illustration of vectors of structures

Execution steps - modular program, Execution steps: Whenever the progr...

Execution steps: Whenever the program is executed, the steps below will take place: The script calcandprintarea starts executing. The calcandprintarea calls the readr

Illustration of subfunctions, Illustration of Subfunctions: This is an...

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

Illustration of gauss-jordan, Illustration of gauss-jordan: Here's an ...

Illustration of gauss-jordan: Here's an illustration of performing such substitutions by using MATLAB >> a = [1 3 0; 2 1 3; 4 2 3] a = 1 3 0 2 1 3 4 2

Illustration of anonymous functions, Illustration of anonymous functions: ...

Illustration of anonymous functions: Dissimilar functions stored in the M-files, when no argument is passed to an anonymous function, the parentheses should still be in the fu

Binary search, Binary Search: The binary search supposes that the vect...

Binary Search: The binary search supposes that the vector has been sorted first. The algorithm is just similar to the way it works whenever looking for a name in a phone direc

Menu driven modular program, Application: Menu driven Modular Program ...

Application: Menu driven Modular Program Numerous longer, more involved programs which have interaction with the user are menu-driven, that means that the program prints a men

Example of image processing, Example of image processing: The other il...

Example of image processing: The other illustration generates a 5 × 5 matrix of arbitrary integers in the range from 1 to the number of colors; the resultant image is as shown

Help command, Help command: The help command is used with the script r...

Help command: The help command is used with the script rectarea, the function readlenwid, and the major function printrectarea. To see the first comment in the subfunction, as

Defined a variable in work space, Defined a variable in work space: Th...

Defined a variable in work space: The variables defined in the script will become a part of the workspace: >> clear >> who >> mysummfile    15 >> who

Illustration of sound signals, Illustration of Sound files: For illust...

Illustration of Sound files: For illustration, the following script generates a subplot which shows the signals from chirp and from train, which is as shown in figure:

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd