How to store vectors as parameters in a matrix

조회 수: 3 (최근 30일)
Faranak Sharifi-Babaki
Faranak Sharifi-Babaki 2019년 1월 30일
댓글: Faranak Sharifi-Babaki 2019년 1월 30일
Hi, I needed help with storing vectors that are passed in my function into a matrix. More specificially, the vectors are of size 4 where
[a1, a2, a3, c]. I wanted to make a 3x3 matrix and a fourth individual vector with the three c (plural)s.
Here is my code:
function [Pspace, Nspace] = a1 (plane1, plane2, plane3);
A = [plane1; plane2; plane3];
Note: I want A to be a 3x3 matrix but each vector passed in has 4 elements!
  댓글 수: 2
James Tursa
James Tursa 2019년 1월 30일
You obviously can't stuff 12 elements into 9 elements. Maybe you could describe the larger problem here and what this function output will be used for, and what the inputs are.
Faranak Sharifi-Babaki
Faranak Sharifi-Babaki 2019년 1월 30일
The function takes as input 3 planes, each specified as a row vector with 4 entries that are interpreted as the coefficients [a1, a2, a3, c]. I am supposed to put the 3 planes in this form: Ax=b
For example if function is called with: a1([1 2 3 4], [2 3 4 5], [ 3 3 3 3] )
I am supposed to turn it into a 3x3 matrix:
1 2 3
A= 2 3 4
3 3 3
and seperate the vector
4
b= 5
3
The function must return two values: the particular solution as a [column] weight vector Pspace and the null solution as a matrix Nspace; the columns of Nspace are weight vectors that are a basis of the null space of the solution.

댓글을 달려면 로그인하십시오.

답변 (1개)

Eugenio Grabovic
Eugenio Grabovic 2019년 1월 30일
A = [plane(1:3);plane2(1:3);plane3(1:3)];
b = [plane1(4);plane2(4);plane3(4)];
Now A is 3x3 matrix and b is 3x1 vector.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by