Write a small piece of the log in a MATLAB program

Source: Internet
Author: User
Tags clear screen modulus

The little knowledge that MATLAB uses:
Ctrl+r: Add multiple lines of comment
Ctrl+t: For the reversal of the Ctrl+r
CLC: Represents the Clear Command window, which clears the current Command Window window, which is clear screen clear all: Clears all loaded data
Ctrl+i: Automatic typesetting




Partition matrix: New_matrix=matrix (Start_line:end_line,start_row:end_row)
Matrix Merge: Column column merge: matrix=[matrix1;matrix2]; line-and-line merge: Matrix=[matrix1,matrix2] or matrix=[matrix1 matrix2]


Instances of the class:
ClassDef Tensiledata
Properties
Material = ' carbon steel ';
Samplenumber = 0;
Stress
Strain
End
Properties (Dependent)
Modulus
End

Methods
function td = Tensiledata (Material,samplenum,stress,strain)
If Nargin > 0
Td. Material = Material;
Td. Samplenumber = Samplenum;
Td. Stress = Stress;
Td. Strain = strain;
End
End% Tensiledata
End

Methods
function obj = set. Material (obj,material)
If ~ (Strcmpi (material, ' aluminum ') | | ...
Strcmpi (material, ' stainless steel ') | | ...
Strcmpi (material, ' carbon steel '))
Error (' Material must be aluminum, stainless steel, or carbon steel ')
End
Obj. Material = Material;
End% Material Set function

function modulus = get. Modulus (obj)
IND = Find (obj. Strain > 0); % Find Nonzero strain
modulus = mean (obj. Stress (Ind)./obj. Strain (Ind));
End% modulus Get function

function obj = set. Modulus (obj,~)
fprintf ('%s%d\n ', ' modulus is: ', obj. Modulus)
Error (' You cannot set modulus explicitly ');
End

Function disp (TD)
fprintf (1, ' Material:%s\nsample number:%g\nmodulus:%1.5g\n ',...
Td. Material,td. Samplenumber,td. modulus);
End% disp

function plot (td,varargin)
Plot (TD. Strain,td. stress,varargin{:})
Title ([' Stress/strain Plot for Sample ', NUM2STR (TD. Samplenumber)])
Xlabel (' Strain% ')
Ylabel (' Stress (PSI) ')
End% plot
End

Methods (Access = ' private ')% access by class members only
function M = Calcmodulus (TD)
% over-simplified calculation of Elastic modulus
IND = FIND (TD. Strain > 0); % Find Nonzero strain
m = Mean (TD. Stress (Ind)./td. Strain (Ind));
End% Calcmodulus
End
End% ClassDef


In the above code,
ClassDef Tensiledata
...
End
is to define a Tensiledata class. Code:
Properties
Material = ' carbon steel ';
Samplenumber = 0;
Stress
Strain
End
Is the attribute that defines the class, which is the member variable of the class in C + +. However, unlike C + +, the class definition in MATLAB has a more special place, that is, to define the dependency property, such as the following code:
Properties (Dependent)
Modulus
End
This means that the Modulus property is a dependency property, and its value is computed from other properties, where the default property value of dependent is true.
Its value is implemented by the following function:
% modulus Get function
function modulus = get. Modulus (obj)
IND = Find (obj. Strain > 0); % Find Nonzero strain
modulus = mean (obj. Stress (Ind)./obj. Strain (Ind));
End
The definition of a method (function) of a class occurs in the form of methods. End. As defined by the following class method:
Methods
function td = Tensiledata (Material,samplenum,stress,strain)
If Nargin > 0
Td. Material = Material;
Td. Samplenumber = Samplenum;
Td. Stress = Stress;
Td. Strain = strain;
End
End
End
The function block defines the Tensiledata constructor method. The last method in the preceding code is methods (Access = ' private ')
Access = ' private ' means that the method can only be accessed and modified by the class itself and is a private member method. Where properties access can also be divided into
Setaccess and Getaccess, the property values are the same as access.
A "..." appears in the DISP function statement to indicate that the next line and the current row are joined together. Such as:
Function disp (TD)
fprintf (1, ' Material:%s\nsample number:%g\nmodulus:%1.5g\n ',...
Td. Material,td. Samplenumber,td. modulus);
End
It means that the second and third rows are joined together.

Write a small piece of the log in a MATLAB program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.