> 其他 >
matlab中如何任意选取一个矩阵的任意几行几列
人气:360 ℃ 时间:2020-06-16 08:03:35
解答
a =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> b=a(3,:) %第三行
b =
4 6 13 20 22
>> c=a(:,3) %第三列
c =
1
7
13
19
25
选取其他行列方法类似请问如果选取的行和列都是不定的,并且选几行几列也是任意的,不一定是一列或一行,要如何实现呢用随机数作为index
clc;clear;
mtx=magic(5);
a=randperm(5);%产生随机行、列数目
index=a(1:2);
temp1=randperm(5);
row=sort(temp1(1:a(1)))
temp2=sort(randperm(5));
col=sort(temp2(1:a(2)))
m1=mtx(row,:)%按行组合
m2=mtx(:,col)%按列组合
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版