2017-08-10 11 views
-1

MATLABで異なる次元を持つ2つの変数を追加する必要があります。行ベクトルと列ベクトルを追加する

A私は和コマンドを使用してそれらを合計することができない、マトリックスの寸法が同じではないので、60 * 1

寸法を有する寸法1×60

Bを有しています。私はそれらを追加する方法があるかどうか尋ねたいと思いますか? transpose function .'またはcolon operator (:)

を使用して

答えて

1

は、次の2行のコードを含めないでください、彼らはこの例のためだけのセットアップです:

A = ones(1, 60); % create an arbitrary row vector 1x60 
B = ones(60, 1); % create an arbitrary column vector 60x1 

は、これらのオプションの、コメントを選択します。それぞれの上には、それが何をしているかが記述さ

% output a vector the same orientation as A 
C = A + B.'; 

% output a vector the same orientation as B 
C = A.' + B; 

% output a column vector, no matter the orientation of A and B 
% Ensure that they are vectors, this will give undesired results if A and B are 2D. 
C = A(:) + B(:); 
関連する問題