How to assign values in an identity matrix?
5 次查看(过去 30 天)
显示 更早的评论
Simple question, but say I have a 3x3 identity matrix:
I = eye(3)
I =
1 0 0
0 1 0
0 0 1
And I want to change the upper right two elements to, say, 2 and 4:
I =
1 0 2
0 1 4
0 0 1
Is there a function that will allow me to do this?
0 个评论
采纳的回答
James Tursa
2018-6-2
编辑:James Tursa
2018-6-2
For this specific question, simple indexed assignment:
I(1:2,end) = [2;4];
But what is your actual problem?
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!