Basic matrix manipulation

Hey, I was wondering if anyone could help me. Ill try to expain it as best i can. A have two matricies. Matrix A (3*4) and matrix B (4*3)
I wish to create matrix C with same size as matrix A that will be made up of values from the first collumn of matrix B. So that if matrix A has a value of 1 value B(1,1) will replace it and so on 2=B(1,2) 3=B(1,2) 4=B(1,1) 0=stays 0
A=[0 1 3 0;0 2 4 0;1 0 0 0]
B=[.3 .5 .6;.4 .6 .1;.5 .5 .5;.5 .2 .5]*
I wish to create C C=[0 .3 .5 0;0 .4 .5 0; .3 0 0 0]
I hope i have expalined it well enough.
Any help would be appreciated. Thank you
Dana Post

 採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 12 月 15 日

0 投票

t = A~=0
C = A;
i1 = 2; % OR 1 or 3
C(t) = B(A(t),i1)

3 件のコメント

Dana
Dana 2011 年 12 月 15 日
Sorry to be a bother im new to all of this. How would i modify this to take the second or third column .
Thanks for your help
Andrei Bobrov
Andrei Bobrov 2011 年 12 月 15 日
Hi Dana! Please see my answer, input variable 'i1' index column of 'B'.
Dana
Dana 2011 年 12 月 16 日
Hey thanks so much. I tried for around 2 hours to do this and wasnt able to figure it out. You saved me a lot of time
Regards
Dana

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by