フィルターのクリア

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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by