How to assign parameters at the same time?

I have a vector v = [1,2,3,4,5] and I would like to do the following in a shorter form (in one line), if possible: a = v(1); second = v(2); v3 = v(3); something = v(4); z = v(5); It would be nice to do like this: [a,second,v3,something,z] = ... ?

 채택된 답변

Star Strider
Star Strider 2015년 5월 26일
편집: Star Strider 2015년 5월 26일

1 개 추천

The deal function exists to do just what you want:
[a,second,v3,something,z] = deal(1,2,3,4,5)
another possibility:
v = [1,2,3,4,5];
vc = mat2cell(v, 1, ones(size(v)));
[a,second,v3,something,z] = deal(vc{:})

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Aerospace Blockset에 대해 자세히 알아보기

질문:

2015년 5월 26일

편집:

2015년 5월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by