フィルターのクリア

Combining two arrays using a seconds order

1 回表示 (過去 30 日間)
Fatih
Fatih 2024 年 2 月 18 日
コメント済み: Fatih 2024 年 2 月 20 日
I have two arrays.
number = [8 9 4 1 2 3 6 7 10 5]
number2 = [5 1 6 7 3 4 10 9 8 2]
I would like to replace the first 5 values of number (8 9 4 1 2)
with the same order for these values in number2 (1 4 9 8 2). So the revised number will be [1 4 9 8 2 3 6 7 10 5] as the next five numbers will not change.
Thanks in advance
  2 件のコメント
Rik
Rik 2024 年 2 月 18 日
Should it only be the first 5 values?
You can use the ismember function to do this. What have you tried so far?
Fatih
Fatih 2024 年 2 月 18 日
thanks, meanwhile I used exactly what you mentioned. The following code worked for me.
++
number = randperm(10, 10)
number2 = randperm(10, 10)
[tf, loc] = ismember(number(1:5), number2)
loc2 = sort(loc)
number = [number2(loc2) number(6:10)]
++

サインインしてコメントする。

採用された回答

Matt J
Matt J 2024 年 2 月 18 日
編集済み: Matt J 2024 年 2 月 18 日
number = randperm(10, 10)
number = 1x10
10 5 4 3 1 9 8 6 2 7
number2 = randperm(10, 10)
number2 = 1x10
8 6 5 3 7 10 2 1 4 9
I=ismember(number2,number(1:5));
number(1:5)=number2(I)
number = 1x10
5 3 10 1 4 9 8 6 2 7
  1 件のコメント
Fatih
Fatih 2024 年 2 月 20 日
thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by