如何根据行列和值生成矩阵?。

2 views (last 30 days)
kpexuq
kpexuq on 21 May 2023
Answered: defour on 21 May 2023
已知excel表中有3列4行矩阵A:
行 列 值
1 3 5 %意思是新矩阵第一行,第三列值为5
1 2 4
2 1 1
2 3 2
想要按照上面行列的号码和值生成新矩阵B:
0 4 5 %按照上面的excel表列、行作为位置坐标生成新矩阵,没有显示行列坐标和值的自动填充0
1 0 2
求赐教从A矩阵变为B矩阵的命令

Accepted Answer

defour
defour on 21 May 2023
仅供参考
A=[1,3,5;
    1,2,4;
    2,1,1;
    2,3,2];
B=zeros(max(A(:,1)),max(A(:,2)));
[r,v] =size(A);
for i=1:r
    B(A(i,1),A(i,2))=A(i,3);
end

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!