Adding each values to row vector

조회 수: 8 (최근 30일)
Duckyoon Go
Duckyoon Go 2021년 3월 27일
댓글: Star Strider 2021년 3월 28일
Hi, I just started to study Matlab and quite confused by vectors.
I am trying to assign values to row vector
[a,b,c]=ones(1,3)
I thought 1 will be assigned to a,b, and c. but error occured saying too many output arguments.
Is there a function to assign multiple values to vector at once?
thanks

채택된 답변

Star Strider
Star Strider 2021년 3월 27일
One option is the deal function:
[a,b,c] = deal(1,2,3)
producing:
a =
1
b =
2
c =
3
.
  댓글 수: 2
Duckyoon Go
Duckyoon Go 2021년 3월 27일
Thank you so much. deal function was exaclty the one I was looking for.
Star Strider
Star Strider 2021년 3월 28일
As always, my pleasure!

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

추가 답변 (1개)

William
William 2021년 3월 27일
... but if you just want to create a vector with three values, you would use a statement like:
a = [1,2,3];
This produces a vector with three elements:
a(1)=1, a(2)=2 and a(3)=3
  댓글 수: 1
Duckyoon Go
Duckyoon Go 2021년 3월 28일
Thank you sir, even though the answer was not what I was looking for, still appreciate your effort. :)

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by