필터 지우기
필터 지우기

Short question: Matrix with two arguments

조회 수: 3 (최근 30일)
MiauMiau
MiauMiau 2013년 1월 5일
Hi
I have seen the following syntax in some places:
[x y]
and was wondering what exactly it means? Something as:
[x y] = [1 5]
doesn't seem to work - so what exactly is this good for? Thanks a lot

채택된 답변

José-Luis
José-Luis 2013년 1월 5일
편집: José-Luis 2013년 1월 5일
It can mean several things.
  • Output of a function:
[x y] = somefunction(arg1, arg2)
The function has two outputs, and one will be saved in x and the other in y
  • Concatenation
newVec = [x y];
The variables x and y are concatenated, provided they have the same size, and assigned to a new variable.
The brackets, however, cannot be used for multiple assignment as you did in your example. For more information look for "square brackets" in the documentation.
  댓글 수: 2
MiauMiau
MiauMiau 2013년 1월 5일
Thanks a lot, that really helped!
Matt J
Matt J 2013년 1월 5일
The brackets, however, cannot be used for multiple assignment as you did in your example.
To accomplish this, you would use DEAL,
>> [x,y]=deal(1,5)
x =
1
y =
5

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

추가 답변 (0개)

카테고리

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