# MATLAB之矩阵

2019/04/10 10:10

（1）删除A的第1、3列 ​A=rand(3,4) ​A(:,[1,3])=[]

A =

``````0.9572    0.1419    0.7922    0.0357

0.4854    0.4218    0.9595    0.8491

0.8003    0.9157    0.6557    0.9340
``````

A =

``````0.1419    0.0357

0.4218    0.8491

0.9157    0.9340
``````

（2）删除B的倒数第三行

``````K=fix(rand(1,10)*10)%%生成随机数
for i=1:10
​if K(i)>3
​k=K(i);
​break;
​end
end
``````

B=rand(k) B(k-2,:)=[]%%删除B的倒数第三行

K =

`````` 4     6     6     6     0     0     3     5     6     4
``````

B =

``````0.8200    0.3251    0.4235    0.2810

0.7184    0.1056    0.0908    0.4401

0.9686    0.6110    0.2665    0.5271

0.5313    0.7788    0.1537    0.4574
``````

B =

``````0.8200    0.3251    0.4235    0.2810

0.9686    0.6110    0.2665    0.5271

0.5313    0.7788    0.1537    0.4574
``````

（1）将字符串中的大写字母变成相应的小写字母，其余字符不变。

``````​ch='i''m A STUDENT'
​lower(ch)
``````

ch =

``````'i'm A STUDENT'
``````

ans =

``````'i'm a student'
``````

``````​ch='i''m A STUDENT'
​k=find(ch>='A'&ch<='Z')
​ch(k)=ch(k)+('a'-'A')
``````

ch =

``````'i'm A STUDENT'
``````

k =

`````` 5     7     8     9    10    11    12    13
``````

ch =

``````'i'm a student'
``````

（2）将子字符串“student”替换为字符串“teacher”

``````​result=strrep( 'i''m a student','student','teacher')
``````

result =

``````'i'm a teacher'
``````

0
0 收藏

0 评论
0 收藏
0