a =
1 3 5 6 7
2 3 2 3 2
5 6 7 8 7
b=
5 2 1 3 7
6 8 2 3 1
5 7 8 6 3
how to swap b to a.
ans=
1 3 5 6 7
2 3 2 3 2
5 6 7 8 7

 採用された回答

Andrew Newell
Andrew Newell 2014 年 4 月 24 日

0 投票

If I understand your latest comment, you begin by finding the unique numbers:
an = unique(a,'stable').'
bn = unique(b,'stable').'
an =
1 3 5 6 7 2 8
bn =
5 2 1 3 7 6 8
Now you take all the 5's in b and replace them by 1's, all the 2's by 3's, and so on, all at once (otherwise in a later step all the 1's will be changed back to 5's). You can do this by initializing a new matrix and putting all the numbers in it:
c = zeros(size(b));
for i=1:length(an)
idx = (b==bn(i));
c(idx) = an(i);
end
c
c =
1 5 7 8 6
2 3 5 8 7
1 6 3 2 8
This seems to be what you're saying, although the result is completely different from the answer you provided.

その他の回答 (1 件)

Andrew Newell
Andrew Newell 2014 年 4 月 23 日

0 投票

I have two theories for what you mean:
b=a
just makes b equal to a. Or
z=b
b=a
a=z
exchanges the two matrices. I think you need to look at a Matlab tutorial or two.

8 件のコメント

Anusha
Anusha 2014 年 4 月 23 日
Receiver side i dont know the a value..i know only b values means.. how to make b to a
Chandrasekhar
Chandrasekhar 2014 年 4 月 23 日
do you want to assign the value of b to a? then you just have to do
a = b;
what is the receiver side variable in your question?
Anusha
Anusha 2014 年 4 月 24 日
I know only b matrix, make to my b matrix to a..
Geoff Hayes
Geoff Hayes 2014 年 4 月 24 日
Are you expecting there to be some sort of general rule or function that maps the elements of b back to the elements of a? An "inverse mapping" of some kind?
Anusha
Anusha 2014 年 4 月 24 日
yes sir
Andrew Newell
Andrew Newell 2014 年 4 月 24 日
If you just supply a single example of a and b, there are an infinite number of rules that could map b to a. Do you have any other information?
Anusha
Anusha 2014 年 4 月 24 日
I use following comments to take a valu an=unique(a,'stable'); bn=unique(b,'stable');
Now swap an and bn in b value. this is useful to get a?
Geoff Hayes
Geoff Hayes 2014 年 4 月 24 日
Was there some sort of suggestion (or part of the problem description) that to do the swap you can use the unique values of a and b (retrieved via stable)?

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

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

質問済み:

2014 年 4 月 23 日

コメント済み:

2014 年 4 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by