Not enough inputs error

조회 수: 8 (최근 30일)
Getty Hill
Getty Hill 2017년 11월 26일
답변: Walter Roberson 2017년 11월 26일
I using a buttonDownFnc on an image set to this function. It is supposed to move the card (image) from one pile to another in an array. I use a bunch of arrays to store everything.
So when I made the function I needed it to reference a few arrays, which are the ones currently listed. However, I am getting a "not enough inputs" even though I call all of them.
In a perfect world, I just set up an if statement to the buttonDownFnc instead of calling a function but from what I have read that isn't an option.
Any help would be amazing!
function flip(played1,Pflip,played2,Cflip,hObject,eventData)
disp(Pflip)
played1 = {played1,Pflip(1,1)};
played2 = {played2,Cflip(1,1)};
Pflip(1)=[];
Cflip(1)=[];
set(imshow(card(53)),'buttonDownFcn',@flip);
end

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 26일
The syntax
set(imshow(card(53)),'buttonDownFcn',@flip);
causes flip to be called with two arguments, sometimes called hObject and eventData. Those two arguments are supplied automatically by MATLAB.
Your line
function flip(played1,Pflip,played2,Cflip,hObject,eventData)
shows that you expect flip to be called with 6 parameters, with hObject and eventData the last two.
You should be using
set(imshow(card(53)),'buttonDownFcn',@(hObject,eventData) flip(played1, Pflip, played2, Cflip, hObject, eventData) );
if you want those arguments to be passed to flip in that order.
Warning: if you do use
set(imshow(card(53)),'buttonDownFcn',@(hObject,eventData) flip(played1, Pflip, played2, Cflip, hObject, eventData) );
then the played1, Pflip, played2, and Cflip that are passed to flip will be the ones that existed at the time the set() call was made, and they will not be updated with any later changes. That is probably want what you want.
I suggest you should be considering using shared variables and nested functions.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by