Posts

Showing posts from October, 2021

basic introduction to table in MatLab

basic introduction to table in MatLab [introduction] What is table? A table is a kind of array in tubular form whose name is it column and it can contain elements with different types. How to create a table? keyword table. Type Conversion. Remember that t1->t2 will be represented as <t1>2<t2> array2table  homogenous array to table. cell2table cell array to table. struct2table structure array to table timetable2table timetable to table. table2array table to homogeneous array. table2cell table to cell array. table2struct  table to structure array. table2timetable table to timetable. How to subscript the type? keyword vartype. [syntax] V=vartype(<type>) V will present as <type> e.g. S = vartype( 'numeric' ); T2 = T(:,S) T will converted as numeric type then assign it to the variable T2. How to convert table to a specified type? keyword convertvars or keyword that I mentioned above. [syntax] T2 = convertvars(T1,vars,dataType) will convert the specified...

comment in MatLab

 inline function in MatLab What is inline function? Inline function in function is like macro in variable. When you use Iinline function, the interpreter will expand the inline function to your code. How to create inline function? keyword inline. [syntax] inline a b will be expanded as b given a [NOTE] It must be seperated by space. more details on: (Not recommended) Construct inline object - MATLAB inline (mathworks.com)

Anonymous Function in MatLab

 Anonymous Function in MatLab [introduction] What is Anonymous Function? It is a function without name. But it is not store in program file. How to create an Anonymous Function? @ [syntax] @funcName content e.g. f=@power2(x) x*x f(x)=power2(x) f(5) will return 5*5 more details on: Anonymous Functions - MATLAB & Simulink (mathworks.com)

a convenient type to record lots of value in MatLab -- cell matrix

a convenient type to record lots of value in MatLab -- cell matrix How to create a cell matrix in MatLab? Way1: cell method Way2: {} more details on: Cell array - MATLAB (mathworks.com) Type Conversion. Remember that when type t1 is converted to type t2 (t1->t2), the keyword is <t1>2<t2> num2cell number array to cell array. char2cell  char array to cell table2cell table to cell array. struct2cell structure array to cell array. mat2cell array to cell array whose cells contains subarrays. cell2num cell array to number array cell2char cell array to char array. cell2table cell array to table. cell2struct cell array to struct array. cell2mat cell array to ordinary array of underlying data type. How to check a type of variable is a cell matrix? iscell() method How to apply each cell in cell array? cellfun method [syntax] cellfun(funcName,arg1) cellfunc(funcName func,arg1) You can declare a anomynous function within the cellfunc method. more details on: Apply function to ea...

How to look at a keyword through code in MatLab? -- MatLab

 How to look at a keyword through code in MatLab? -- MatLab If you wanna learn about this keyword, you can use help cmd e.g. I wanna know syms cmd. I can write the following line. help syms And I will see the output. syms   Short-cut for constructing symbolic variables.     syms arg1 arg2 ...     is short-hand notation for creating symbolic variables        arg1 = sym('arg1');        arg2 = sym('arg2'); ...     or, if the argument has the form f(x1,x2,...), for     creating symbolic variables        x1 = sym('x1');        x2 = sym('x2');        ...        f = symfun(sym('f(x1,x2,...)'), [x1, x2, ...]);     The outputs are created in the current workspace.       syms  ... ASSUMPTION     additionally puts an assumption on the variables created.     The ASSUMPTION can ...

How to clear command window through code in MatLab? -- MatLab

 How to clear command window through code in MatLab? -- MatLab clc

How to clear workspace through code in MatLab? -- MatLab

 How to clear workspace through code in MatLab? -- MatLab clear

How to solve equation with MatLab?

 How to solve equation with MatLab? It is quite simple. Way1: using solve method. Step1: Declare symbolic variable. Step2: Declare the equation. Step3: using solve method. Then you will get a struct field.  I wanna solve the system of equations. I write the following code. %clear workspace   clear   %clear command window   clc       % way1:   %solve it   syms x y  z;   equ1=3*x-3*y+z==2   equ2=x-y+z==1   equ3=7*x+5*y-z==-5       %find a solution of equation   sol=solve ([ equ1,equ2,equ3 ], [x,y,z ])   %ans   x=sol.x   y=sol.y   z=sol.z   [NOTE] syms must be seperated in space instead of ','. such as syms x,y,z; is not acceptable. Want to learning a lot? I recommend you to take a look at them. Solve System of Linear Equations - MATLAB & Simulink (mathworks.com) or How to Solve Simultaneous Equations in MatLAB Using linsolve and solve - YouTube

MatLab HW1 CH4-6

Image
  MatLab HW1 CH4-6   -- 40843245   preface this is my ans of HW in numerical analysis. I don't put my question in this article. I just put my answer. Question in the reference book in the following link. info HW1 CH4-6 HW Date:2021/10/22-2021/10/29 Reference Book 博客來-MATLAB程式設計實務(第五版)(附範例光碟) (books.com.tw) CH4-6    [Code]   %MatLab HW CH4-6   %HW Date:2021/10/22       %clear workspace   clear   %clear command window   clc       %create a symbolic variable   x=sym  (' x ') ;   C( x) =0.1*x^2+7*x+ 210;   vec1=[1:2:30 ];   %ans   y=C( vec1)     [Ans]   y=   [2171/10, 2319/10, 495/2, 2639/10, 2811/10, 2991/10, 3179/10, 675/2, 3579/10, 3791/10, 4011/10, 4239/10, 895/2, 4719/10, 4971/10]     CH4-26   [Code]   %MatLab HW CH4-26   %HW Date:2021/10/22       %clear workspace   clear   %clear command window   clc ...