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

2 次查看(过去 30 天)
kpexuq
kpexuq 2023-5-21
回答: defour 2023-5-21
已知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矩阵的命令

采纳的回答

defour
defour 2023-5-21
仅供参考
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!