How to replace values in a matrix with another set of values

2 次查看(过去 30 天)
Hi,
I have a 91282 x 1 matrix and I want to replace the specific values 59688:60003 (n=315) with another set of 315 numbers (a 315 x 1 matrix) in those exact places. What is the best way of doing this? Thanks!

采纳的回答

Image Analyst
Image Analyst 2018-10-18
Try this
% Stuff sourceVector into indexes 59688:60003 of targetVector
targetVector(59688:60003) = sourceVector;
  3 个评论
Jan
Jan 2018-10-18
编辑:Jan 2018-10-18
@bsriv: Note that 59688:60003 has 316 elements, not 315. So if you want to insert 315 elements starting from element 59688:
len = numel(sourceVector);
targetVector(59688:(59688 + len - 1)) = sourceVector;
% ^^^ essential!

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2018-10-18
You can use the intlut() function.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by