필터 지우기
필터 지우기

Can matlab assign a vector of objects?

조회 수: 2 (최근 30일)
Jacob Thompson
Jacob Thompson 2020년 4월 6일
댓글: Tommy 2020년 4월 6일
[x,y,z] = [1,2,3]
Say I want to assign the objcts x, y, and z to values 1,2,3
Can I create a vector of objects [x,y,z] and assign it [1,2,3]? Why does
[x,y,z] = [1,2,3] not work? Surely I dont have to laboriously type out
x = 1
y = 2
z = 3
yes?

답변 (1개)

Tommy
Tommy 2020년 4월 6일
One possibility...
C = num2cell([1 2 3]);
[x,y,z] = C{:};
  댓글 수: 2
Jacob Thompson
Jacob Thompson 2020년 4월 6일
Is there an inverse operation that can undo num2cell?
Tommy
Tommy 2020년 4월 6일
Yes, cell2mat:
>> num2cell([1 2 3])
ans =
1×3 cell array
{[1]} {[2]} {[3]}
>> cell2mat(ans)
ans =
1 2 3

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by