DataStructure (MATLAB)
DataStructure (MATLAB)
with MATLAB
CONTACT SESSION 14
Dr.Pankaj Wankhede
BITS Pilani
Pilani | Dubai | Goa | Hyderabad WILP – BITS Pilani
Computer Programming
with MATLAB
Cell Array
Creating a row vector cell array
Creating a column vector cell array
Cell array Matrix
Display all the contents of Cell Array
Structures
Creating a structure
Add a new field to structure
Remove a field from structure
Creating Structure of more than one record
Examples
>>package.name = ‘JAVA’
package =
item_no: 123
cost: 19.9900
price: 39.9500
code: 'g'
name: 'JAVA '
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Remove a Field from Structure
This is done using rmfield:
>>rmfield(package,‘code’)
package =
item_no: 123
cost: 19.9900
price: 39.9500
name: 'JAVA '
cyls(1) = struct('code','x','dimensions',struct('rad',3,'height',6),'weight',7);
cyls(2) = struct('code','a','dimensions',struct('rad',4,'height',2),'weight',5);
cyls(3) = struct('code','c','dimensions',struct('rad',3,'height',6),'weight',9);
for i=1:length(cyls)
x = cyls(i).dimensions;
volume = pi*(x.rad)*(x.rad)*x.height;
fprintf('Cylinder with code %s having volume %.2f\n', cyls(i).code,volume)
end