defining a vector with vector of indices

6 ビュー (過去 30 日間)
ss
ss 2012 年 12 月 26 日
Hi all
I have a vector zero of size M called A, also I have another vector of size 4 that its arrays are integers among 1 to M called B. now I want to put some values in arrays of A with indeces in B, I.e I want to put values in 4 place of A, that these places are defined via B, for instace:
A=zeros(8,1), and B=[ 1 3 4 5], I want to put some defined numbers in positions 1, 3, 4 and 5 of A, how I can do that?
is there anyone to help me?
Thank you

採用された回答

Matt J
Matt J 2012 年 12 月 26 日
A(B)=whatever
  2 件のコメント
ss
ss 2012 年 12 月 26 日
thank you very much Matt
ss
ss 2012 年 12 月 27 日
matt if we have a matrix and we want to change the position of its array, rows and columns simultaneously, using two index vector B1 and B2, how can we use this command, i.e for instance u=[u11 u12 u13 u14;u21 u22 u23 u24;u31 u32 u33 u34;u41 u42 u43 u44]; B1=[1 4 3 2] B2=[3 2 1 4](B1 and B2 themselves are columns of a matrix) such that B1 is used for changing rows and B2 for changing columns, so u would be u=[u13 u12 u11 u14;u43 u42 u41 u44;u33 u32 u31 u34; u23 u22 u21 u24] thanks

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2012 年 12 月 26 日
編集済み: Andrei Bobrov 2012 年 12 月 26 日
A(B) = C;
here C - with size(C) = [1,1] or numel(C) == numel(B)
  1 件のコメント
ss
ss 2012 年 12 月 26 日
yes, this works, thank you very much Andrei

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

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by