Matlab sparse matrix does not come out as I would expect
1 次查看(过去 30 天)
显示 更早的评论
This is my code:
S=sparse([1 3 2 1 4],[3 1 4 1 4],[1 2 3 4 5],4,4)
full(s)
However, when I run it, I get:
'S =
(1,1) 4
(3,1) 2
(1,3) 1
(2,4) 3
(4,4) 5
ans=
0 0 0 1
0 1 0 0
1 2 0 0
0 0 3 0'
Please tell me why ans is not [4 0 1 0;0 0 0 3; 2 0 0 0; 0 0 0 5]?
0 个评论
采纳的回答
John D'Errico
2025-2-3
编辑:John D'Errico
2025-2-3
S=sparse([1 3 2 1 4],[3 1 4 1 4],[1 2 3 4 5],4,4)
full(S)
It works just fine.
What did you do wrong? LOOK CAREFULLY AT WHAT YOU WROTE. MATLAB is case sensitive in variable names.
You created the matrix S. Then you looked at full(s). Should MATLAB know that you wanted to see what was in the variable S, and not in the variable s? The mind reading toolbox never works correctly. ;-)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!