how to fill a vector with another ones

4 ビュー (過去 30 日間)
bay rem
bay rem 2015 年 12 月 23 日
編集済み: bay rem 2015 年 12 月 23 日
hello everyone i have two vectors:
A=[ X Y Z T ]
B=[ X' Y' Z' T' ]
i wanna create a vectors
C1=[X X']
C2=[Y Y']
C3=[Z Z']
C4=[T T']

採用された回答

the cyclist
the cyclist 2015 年 12 月 23 日
編集済み: the cyclist 2015 年 12 月 23 日
A = [ 1 2 3 4];
B = [ 5 6 7 8];
N = numel(A);
C = cell(N,1);
for ni = 1:N
C{ni} = [A(ni) B(ni)]
end
It is generally a poor idea to name variables C1, C2, etc. There are lots posts here about that fact.
Instead, a better solution is to use cell arrays, that can store vectors (and other object) in their elements.
Later in your code, simply refer to C{1}, which is the contents of the first element in C, in the same way you would have used C1.
  2 件のコメント
bay rem
bay rem 2015 年 12 月 23 日
編集済み: bay rem 2015 年 12 月 23 日
If
A=[ 23 45 57 77 ]
B=[ 34 4 657 7 ]
  • i wanna create 4 vectors
C1=[23 34]
C2=[45 5]
C3=[57 657]
C4=[77 7]
bay rem
bay rem 2015 年 12 月 23 日
編集済み: bay rem 2015 年 12 月 23 日
A=[1,2,3,4] 
B=[4,5,6,7]
  • so the solution is,
C1=[A(1),B(1)]
C2=[A(2),B(2)]
C3=[A(3),B(3)]
C4=[A(4),B(4)]

thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by