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

该博客围绕Matlab在机器学习中的应用展开,介绍了如何加载、保存数据,查看Matlab工作区变量信息,还讲解了矩阵元素索引、行列赋值、追加行列、矩阵拼接等操作,最后提供了Coursera上的资源链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Matlab Commands

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值