why does the function in my programming get an error with the description 'Not enough input arguments.'?
Afficher commentaires plus anciens
why does the function in my programming get an error with the description 'Not enough input arguments.' please explain why this can be an error and how to fix it? I am using matlab R2015a.
function letter = readLetter(snap)
load NewTemplates
snap=imresize(snap,[42 24]);
comp=[ ];
for n=1:length(NewTemplates)
sem=corr2(NewTemplates{1,n},snap);
comp=[comp sem];
end
vd=find(comp==max(comp));
if vd==1 || vd==2
letter='A';
elseif vd==3 || vd==4
letter='B';
elseif vd==5
letter='C';
elseif vd==6 || vd==7
letter='D';
elseif vd==8
letter='E';
elseif vd==9
letter='F';
elseif vd==10
letter='G';
elseif vd==11
letter='H';
elseif vd==12
letter='I';
elseif vd==13
letter='J';
elseif vd==14
letter='K';
elseif vd==15
letter='L';
elseif vd==16
letter='M';
elseif vd==17
letter='N';
elseif vd==18 || vd==19
letter='O';
elseif vd==20 || vd==21
letter='P';
elseif vd==22 || vd==23
letter='Q';
elseif vd==24 || vd==25
letter='R';
elseif vd==26
letter='S';
elseif vd==27
letter='T';
elseif vd==28
letter='U';
elseif vd==29
letter='V';
elseif vd==30
letter='W';
elseif vd==31
letter='X';
elseif vd==32
letter='Y';
elseif vd==33
letter='Z';
elseif vd==34
letter='1';
elseif vd==35
letter='2';
elseif vd==36
letter='3';
elseif vd==37 || vd==38
letter='4';
elseif vd==39
letter='5';
elseif vd==40 || vd==41 || vd==42
letter='6';
elseif vd==43
letter='7';
elseif vd==44 || vd==45
letter='8';
elseif vd==46 || vd==47 || vd==48
letter='9';
else
letter='0';
end
end
4 commentaires
Torsten
le 14 Août 2023
Did you call the function from a script with an appropriate input for "snap" ? Otherwise: how should the function work without input ?
Amelinda Callista
le 20 Août 2023
Walter Roberson
le 21 Août 2023
Why does everyone use that verbose code??
function letter = readLetter(snap)
load NewTemplates
snap=imresize(snap,[42 24]);
comp=[ ];
for n=1:length(NewTemplates)
sem=corr2(NewTemplates{1,n},snap);
comp=[comp sem];
end
vd=find(comp==max(comp));
LETS = 'AABBCDDEFGHIJKLMNOOPPQQRRSTUVWXYZ123445666788999';
if vd <= length(LETS)
letter = LETS(vd);
else
letter = '0';
end
Amelinda Callista
le 22 Août 2023
Réponses (1)
Sulaymon Eshkabilov
le 14 Août 2023
What Torsten has suggested is somewhat like this one. And addionally, it is better to have two input arguments (to be called, or existing in the workspace), e.g.:
NewTemplates = load('XXXXX.mat'); % mat or ASCII formatted *.dat files can be loaded
letter = readLetter(snap, NewTemplates);
function letter = readLetter(snap, NewTemplates)
snap=imresize(snap,[42 24]);
...
end
7 commentaires
Amelinda Callista
le 20 Août 2023
I guess you mean "row" instead of "column" ?
Which MATLAB version do you use ?
Walter Roberson
le 20 Août 2023
you are using r2015a. But r2015b was the first release that permitted defining functions inside scripts. You need to put the function in its own file in your release.
Torsten
le 20 Août 2023
I wonder why the above link is not yet updated (at least said that it's only relevant for releases <= 2015a).
Amelinda Callista
le 21 Août 2023
"what version of matlab should I use so that the function doesn't have problems?"
MATLAB has supported functions for a very long time (certainly well before your version), so there is nothing stopping you from creating a function in its own file and then calling it, exactly as Walter Roberson commented here.
Amelinda Callista
le 21 Août 2023
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!