필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
bsriv
bsriv 2018년 10월 17일
댓글: bsriv 2018년 10월 18일
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!
  댓글 수: 2
Jan
Jan 2018년 10월 18일
Do you mean the values 59688:60003, or are these the indices of the values you want to replace?
bsriv
bsriv 2018년 10월 18일
Sorry, yeah I meant the indices

댓글을 달려면 로그인하십시오.

채택된 답변

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!
bsriv
bsriv 2018년 10월 18일
Got it... thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (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