吴恩达机器学习笔记--Matlab commands

Matlab Commands

文章目录

  • How to load data?
  • How to check the variables and their info in my Matlab workspace?
  • How do we save data?
  • how to index an element in a matrix?
  • Then what if we want to get the first and the third row of A?
  • How can we make an assignment to a row/column?
  • How to append another row/column to A?
  • How to put all of elements of A into a single vector?
  • How to concatenate two matrix?
  • resource link from Coursera

How to load data?

>>>load file_name.extension
>>>load('file_name.extension')

How to check the variables and their info in my Matlab workspace?

>>> who
>>> whos
‘who’ command shows what variables I have in my Matlab workspace.

‘whos’ gives me the detailed view of variables, including ‘Attr names’, ‘size’, ‘bytes’, ‘class’.
Here ‘class’ means ‘double’ or ‘char’ …

How do we save data?

format:
>>> save file_name.extension variable_name
such as:
>>> save hello.mat A
or:
>>> save hello.txt A -ascii % Here '-ascii' makes it readable for human

how to index an element in a matrix?

suppose that A is [1 2; 3 4; 5 6;]
then if we want to index (3,2), which is 6, we just need to write:
>>> A(3,2)

and if we want to index the second row of A, which is ‘3 4’, we need to write:
>>> A(2,:) % Here ':' means every element along that row/colomun
Similarily, if we want to index the second column of A, which is ‘2 4 6’, what we need it to write:
>>> A(:,2)

Then what if we want to get the first and the third row of A?

Just write:
>>> A([1 3], :)

How can we make an assignment to a row/column?

>>> A(:,2) = [11; 12; 13]

How to append another row/column to A?

>>> A = [A, [101; 102; 103]] % Note that here we use ';' rather than ','

How to put all of elements of A into a single vector?

>>> A(:)

How to concatenate two matrix?

Suppose that B is equal to [11 12; 13 14; 15 16]
then:
>>> C = [A B] % Concatenating A and B matrices side by side
Now, C is supposed to be [1 2; 3 4; 5 6; 11 12; 13 14; 15 16]
the command above is equal to this:
>>> C = [A, B] % Concatenating A and B matrices side by side
What about this:
>>> C = [A; B] % Concatenating A and B top and bottom

resource link from Coursera

when I typed here, I found that all codes are actually posted in this site. So if there are any questions or doubts, just search for it by looking into this link:
https://www.coursera.org/learn/machine-learning/resources/QQx8l

你可能感兴趣的:(机器学习)