How to replace certain rows in a matrix with the same row vector?
显示 更早的评论
I have a 100 x 3 matrix that I first fill with a repeating row vector:
colours = repmat([1, 0, 0], 100, 1)
I then want to replace selected, non-contiguous rows of the matrix with a different row vector. Which rows should be replaced is determined by a 100 x 1 logical. The following code gives a dimension mismatch (I understand why):
colours(logical(data(:, 18)), :) = [0 1 0];
Is there a way to achieve this without a loop?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!