台大郭彦甫_MATLAB视频笔记(三)变数(变量)与档案存取

这一个视频的内容其实比较多,涉及到MATLAB中多种变量的类型,string、structure、cell array,很多内容我觉得在于理解,笔记记得不是很多,需要的时候自己再去找资料看。

1.MATLAB中的变量类型有多种,numeric(数值类型)默认为double类型。
2.定义cell array(元胞数组)类型变量的方法,有两种,主要就是大括号的位置不同
第一种方法

A(1,1)={[1 4 3; 0 5 8; 7 2 9]};
A(1,2)={'Anne Smith'};
A(2,1)={3+7i};
A(2,2)={-pi:pi:pi};


第二种方法

A{1,1}=[1 4 3; 0 5 8; 7 2 9];
A{1,2}='Anne Smith';
A{2,1}=3+7i;
A{2,2}=-pi:pi:pi;


3.如何查看cell array(元胞数组)的内容?
方法:采用大括号来查看,如A{1,1},A{1,2}等
4.cat()函数的用法
cat()函数用于连接两个array,即array concatenation,需要注意的是连接的方向
C = cat(1,A,B)
C = cat(2,A,B)
C = cat(3,A,B)
A,B是需要连接的两个矩阵,cat()第一个参数表示连接的方向;
1:沿着行row的方向连接;2:沿着列column的方向连接;3.沿着layer的方向连接。

附带自己写的练习题答案
exercise 1:
题目:
• Write a script that inverts any given string
s1='I like the letter E'
s2='E rettel eht ekil I'
代码:

s1 = 'I like the letter E';
s2 = '';
len = length(s1);
disp(len);
for ii = 1:1:len
    s2(ii) = s1(len+1-ii);
end
disp(s2);

exercise 2:
题目:
Create a cell array B that has the following 
structure
代码:

B{1,1} = 'This is the first cell';
B{1,2} = [5+j*6, 4+j*5];
B{2,1} = [1 2 3; 4 5 6; 7 8 9];
B{2,2} = ['Tim', 'Chris'];
B


B(1,1) = {'This is the first cell'};
B(1,2) = {[5+j*6, 4+j*5]};
B(2,1) = {[1 2 3;4 5 6;7 8 9]};
B(2,2) = {['Tim', 'Chris']};
B

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值