function deal()

조회 수: 5 (최근 30일)
Yin
Yin 2011년 6월 6일
I'm having trouble getting deal() to place one number in multiple places. My lines of code:
y1=[];
y2=[];
y3=[];
y={y1 y2 y3};
y=deal(5);
gives me the error: The right hand side of this assignment has too few values to satisfy the left hand side.
  댓글 수: 1
Yin
Yin 2011년 6월 6일
er, sorry, the final line should read:
y{:}=deal(5);

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

채택된 답변

Matt Fig
Matt Fig 2011년 6월 6일
y = cell(1,3); % dispense with the y1, y2, y3 stuff....
[y{:}] = deal(5)
or, without defining the variable first:
[Y{1:3}] = deal(5) % Y is not defined before this line..
But why use DEAL at all?
y = cell(1,3);
y(:) = {9}
  댓글 수: 1
Yin
Yin 2011년 6월 6일
That's awesome, I can't read, lol.
I'm actually trying to figure out how to create a pointer-like structure where values can be dynamically changed without knowing all the variables that "point" to it.
Thanks for your help.

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

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by