MATLAB Object-Oriented Programming
Example Code Discussion properties Material SampleNumber Stress Strain end See “Structure of the Data” on page 3-19 properties ( ...
Example Code Discussion function m = get.Modulus(obj) ind = find(obj.Strain > 0); m = mean(obj.Stress(ind)./obj.Strain(ind)); ...
Expand for Class Code classdef TensileData properties Material SampleNumber Stress Strain end properties (Dependent) Modulus end ...
sprintf('Material: %s\nSample Number: %g\nModulus: %1.5g\n',... td.Material,td.SampleNumber,td.Modulus) end function plot(td,var ...
Implementing Linked Lists with Classes In this section... “Class Definition Code” on page 3-31 “dlnode Class Design” on page 3-3 ...
Data — Contains the data for this node Next — Contains the handle of the next node in the list (SetAccess = private) Prev — Con ...
n2.insertAfter(n1) % Insert n2 after n1 n3.insertAfter(n2) % Insert n3 after n2 Now the three nodes are linked: n1.Next % Points ...
Why a Handle Class for Linked Lists? Each node is unique in that no two nodes can be previous to or next to the same node. For e ...
Example Code Discussion classdef dlnode < handle “dlnode Class Design” on page 3-31 “Why a Handle Class for Linked Lists?” on ...
Example Code Discussion function insertBefore(newNode, nodeAfter) removeNode(newNode); newNode.Next = nodeAfter; newNode.Prev = ...
Expand for Class Code classdef dlnode < handle % dlnode A class to represent a doubly-linked node. % Link multiple dlnode obj ...
% Remove a node from a linked list. if ~isscalar(node) error('Input must be scalar') end prevNode = node.Prev; nextNode = node.N ...
Class Properties Only dlnode class methods can set the Next and Prev properties because these properties have private set access ...
How insertAfter Works First, insertAfter calls the removeNode method to ensure that the new node is not connected to any other n ...
Remove a Node The removeNode method removes a node from a list and reconnects the remaining nodes. The insertBefore and insertAf ...
n3 Properties Next Prev n2 Properties Next Prev n1 Properties Next Prev Disconnect the nodes removeNode removes n2 from the list ...
head.Next.Next ans = dlnode with properties: Data: 4 Next: [1x1 dlnode] Prev: [1x1 dlnode] And the previous node has a Data valu ...
n3 Properties Next Prev n2 Properties Next Prev n2 Properties Next Prev n1 Properties Next Prev >> removeNode(n2) >> ...
removeNode(node); end while ~isempty(prev) node = prev; prev = node.Prev; removeNode(node) end end For example, suppose that you ...
head head = dlnode with properties: Data: 1 Next: [] Prev: [] nextNode nextNode = dlnode with properties: Data: 2 Next: [] Prev: ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf