How do you change an entire row or column of an array to a certain value
161 次查看(过去 30 天)
显示 更早的评论
If I have an array of all zeros X = zeros(N) How do I change a column to a value I want.
0 个评论
采纳的回答
Star Strider
2017-9-15
One option:
N = 5;
X = zeros(N);
X(:,3) = rand(N, 1); % Change Column #3 To A Specific Vector
X(2,:) = 5*ones(1, N); % Change Row #2 To a Row Of ‘5’
4 个评论
Star Strider
2023-9-13
@Riley Harris — Yes, however it can easily be vectorised. Using the sub2ind function is another option.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!