如何寻找矩阵中一列顺序数缺失的数值并进行插值?。
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
果博东方开户账号【微8785092】
il 23 Mag 2023
Risposto: 果博东方注册官网【微8785092】
il 23 Mag 2023
我这里有一个矩阵,他按照第一列顺序排列,但是其中有些缺失的数值,我需要把缺失的数值对应的行设为0,请问如何操作?
例子:这里有矩阵A,他按照第一列的从小到大顺序进行排列
A=[1 2 3;3 5 6;4 9 5;5 9 9]
A =
1 2 3
3 5 6
4 9 5
5 9 9
我们可以看到第一列缺失了'2’,所以我需要把矩阵变为(把缺失的第二行变为0),其他行往下移动
A =
1 2 3
0 0 0
3 5 6
4 9 5
5 9 9
请问如何做到这种效果
0 Commenti
Risposta accettata
果博东方注册官网【微8785092】
il 23 Mag 2023
A=[1 2 3;3 5 6;4 9 5;5 9 9];
[m,n]=size(A);
A=sortrows(A,1);
[t1,t2]=ismember(min(A(:,1)):max(A(:,1)),A(:,1))
B=zeros(length(t1),n);
B(t1,:)=A
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!