The matrix X is randomly shuffled, how does Y follow up that shuffle?
i.e:
X=[4 7 1 9;
3 0 6 8]
Y=[32 6 4 21;
77 89 0 2]
after the shuffle:
X=[3 9 4 6;
1 7 8 0]
Y=[77 21 32 0;
4 6 2 89]

 採用された回答

Guillaume
Guillaume 2018 年 11 月 30 日

2 投票

X = [4 7 1 9;
3 0 6 8]
Y = [32 6 4 21;
77 89 0 2]
newX = [3 9 4 6;
1 7 8 0]
[found, where] = ismember(newX, X);
assert(all(found(:)), 'some elements of newX are not present in X')
newY = Y(where)

3 件のコメント

Hugo Matias
Hugo Matias 2018 年 11 月 30 日
Thank you sir
Hugo Matias
Hugo Matias 2018 年 12 月 1 日
編集済み: Guillaume 2018 年 12 月 2 日
Hi, how do I do the same thing but instead of that this:
(imagine "a" as a number)
How do I do this?
X=[4 7 1 0;
3 0 6 8]
Y=[32 6 4 21;
77 89 0 2]
X(X==0)=a;
after the alteration:
X=[4 7 1 a;
3 a 6 8]
Y=[ 32 6 4 a;
77 a 0 2];
Guillaume
Guillaume 2018 年 12 月 2 日
Keep the list of elements you're going to replace (i.e. the logical array X == 0) so that you can use for Y as well:
X=[4 7 1 0;
3 0 6 8]
Y=[32 6 4 21;
77 89 0 2]
toreplace = X == 0;
X(toreplace) = a;
Y(toreplace) = a;

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 30 日
編集済み: madhan ravi 2018 年 11 月 30 日

0 投票

X=[4 7 1 9;
3 0 6 8]
idx=randsample(1:numel(X),numel(X));
shuffled_X=reshape(X(idx),size(X,1),[])
Y=[32 6 4 21;
77 89 0 2]
shuffled_Y=reshape(Y(idx),size(Y,1),[])
command window:
>> COMMUNITY
X =
4 7 1 9
3 0 6 8
shuffled_X =
1 0 3 7
8 9 4 6
Y =
32 6 4 21
77 89 0 2
shuffled_Y =
4 89 77 6
2 21 32 0
>>

1 件のコメント

Hugo Matias
Hugo Matias 2018 年 11 月 30 日
I didn't mean shuffled like that, sorry!
I mean I change the numbers positions of the matrix X
and matrix Y will replicate the movements

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

カテゴリ

タグ

質問済み:

2018 年 11 月 30 日

コメント済み:

2018 年 12 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by