mapping between two different matrices

8 ビュー (過去 30 日間)
Supriya Gain
Supriya Gain 2023 年 4 月 24 日
回答済み: Kevin Holly 2023 年 4 月 24 日
I have a matrix a=[1 2;3 4;5 6] and i have another matrix b=[1 2 3;1 2 3;1 2 3;1 2 3;1 2 3]. Now I want to map between two matrices in such a way that the first row of matrix 'a' is indicating the first column of matrix 'b'. Like, if I type [1 2], it should show [1;1;1;1;1]. If I type [3 4] it should show [2;2;2;2;2].
How to do that?

採用された回答

Fangjun Jiang
Fangjun Jiang 2023 年 4 月 24 日
a=[1 2;3 4;5 6];
b=[1 2 3;1 2 3;1 2 3;1 2 3;1 2 3];
c=[1 2];
[~,index]=ismember(c,a,'rows');
b(:,index)
ans = 5×1
1 1 1 1 1

その他の回答 (2 件)

Kevin Holly
Kevin Holly 2023 年 4 月 24 日
a=[1 2;3 4;5 6]
a = 3×2
1 2 3 4 5 6
b=[1 2 3;1 2 3;1 2 3;1 2 3;1 2 3]
b = 5×3
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
index = 3;
output = yourmap(a,b,index)
output = 5×1
2 2 2 2 2
index = 6;
output = yourmap(a,b,index)
output = 5×1
3 3 3 3 3
index = [1 2];
output = yourmap(a,b,index)
output = 5×2
1 1 1 1 1 1 1 1 1 1
function output = yourmap(a,b,index)
[row,column] = find(a==index);
output = b(:,row);
end

Walter Roberson
Walter Roberson 2023 年 4 月 24 日

カテゴリ

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