Assign variables to positions in matrix

4 ビュー (過去 30 日間)
Patrick Star
Patrick Star 2011 年 3 月 25 日
I'm sure this is a stupid question, but how does one define variables as positions in a matrix? For example, in matrix algebra, if I set up a matrix equation such that B=inv(A)*C, how can I define x and y such that B=[x;y]?

採用された回答

David Young
David Young 2011 年 3 月 25 日
Alternatively, do you mean that you have B and want to divide it into two parts? If B is 2x1 or 1x2 you can do
x = B(1);
y = B(2);
More generally, if you want to split B into a top half and a bottom half, you could do
splitrow = ceil(size(B, 1)/2);
x = B(1:splitrow, :);
y = B(splitrow+1:end, :);
This divides B in half, as far as possible. Your condition B=[x;y] is satisfied for any legal value of splitrow.
  1 件のコメント
Patrick Star
Patrick Star 2011 年 3 月 31 日
Thanks! x=B(1) and y=B(2) is exactly what I was looking for.

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

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2011 年 3 月 25 日
B = [3;4]; %column vector
B = [3 4]; %row vector
B = [1 2; 3 4]; %2x2 matrix.
Ps
B = A\C; %is better than inv(A)*C
  2 件のコメント
Patrick Star
Patrick Star 2011 年 3 月 31 日
I know how to create a matrix, but I just need to know how to assign variables to values in a matrix.
Also, B=C/A does not work because you cannot divide matrices like that with different dimensions.
Sean de Wolski
Sean de Wolski 2011 年 3 月 31 日
Note the difference in our slashes \/!

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

カテゴリ

Help Center および 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