输入参数过多 [英] Too many input arguments
问题描述
我收到以下关于fprintf函数中输入参数过多的错误消息.但是在我看来,只是传递了正确数量的参数.
I get the following error message about too many input arguments in my fprintf function. But it seems to me that just the right amount of arguments were passed.
所有这些都是在我制作的指南GUI的上下文中完成的(请参见最后的图片).
All this is in the context of a guide GUI I made (see picture at the end).
Error while evaluating uicontrol Callback
calibration button hit
20
200
10
10
2520
25197
2520
25197
'C0 2520 25197 10 10'
Error using serial/fprintf (line 115)
Too many input arguments.
Error in UserInterface>StaticCalibrationBtn_Callback (line 202)
fprintf(handles.s, 'C0 %s %s %s %s',StartStepsStr,EndStepsStr,Increment,Wait);
这是代码
function StaticCalibrationBtn_Callback(hObject, eventdata, handles)
% hObject handle to StaticCalibrationBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('calibration button hit');
Start = str2double(get(handles.CalFromUserTxt, 'string')); % Fetches the user inputed start location in mm and converts to double
disp(Start);
End = str2double(get(handles.CalToUserTxt, 'string')); % same for End position
disp(End);
Increment = get(handles.CalUserIncrementTxt, 'string'); % fetches the increment user inputed data as a string
disp(Increment);
Wait = get(handles.CalUserSpeedTxt, 'string'); % fetches the wait inputed data as a string
disp(Wait);
StartSteps = round(Start/0.00793750000); % computes the starting step position,double division
disp(StartSteps);
handles.StartSteps = StartSteps; % creats a place for the start steps inside the handles structure, to be fetched by anythingelsest be saved with guidata(hObject,handles)
EndSteps = round(End/0.00793750000); % computes the end step position
disp(EndSteps);
handles.EndSteps = EndSteps; % stores the end steps to be accessed by anything else must be saved with guidata(hObject,handles)
StartStepsStr = num2str(StartSteps); % converts the StartSteps double into a string so it can be sent over serial as a string
disp(StartStepsStr);
EndStepsStr = num2str(EndSteps); % converts the EndSteps double into a string so it can be sent over serial as a string
disp(EndStepsStr);
OutputString = strcat('C0' , {' '} , StartStepsStr , {' '} , EndStepsStr , {' '} , Increment , {' '} , Wait);
disp(OutputString);
fprintf(handles.s, 'C0 %s %s %s %s',StartStepsStr,EndStepsStr,Increment,Wait);
handles.s的来源
and where handles.s comes from
function SerialBtn_Callback(hObject, eventdata, handles)
% hObject handle to SerialBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA
comPort = get(handles.COMportTxt,'String');
if(~exist('serialFlag','var'))
[handles.s, handles.serialFlag] = setupSerial(comPort);
end
guidata(hObject,handles);
end
还有设置串行功能
function [ s, flag] = setupSerial(comPort)
%Initialize serial port communication between Arduino and Matlab
%Ensure that the arduino is also communicating with Matlab at this time.
%if setup is complete then the value of setup is returned as 1 else 0.
flag =1;
s = serial(comPort);
set(s,'DataBits',8);
set(s,'StopBits',1);
set(s,'BaudRate',9600);
set(s,'Parity','none');
fopen(s);
a='b';
while (a~='a')
a=fread(s,1,'uchar');
end
if (a=='a')
disp('serial read');
end
fprintf(s,'%c','a');
mbox = msgbox('Serial Communication setup.'); uiwait(mbox);
fscanf(s,'%u');
end
使用以下已解决的问题
OutputString = sprintf('C0 %s %s %s %s',StartStepsStr,EndStepsStr,Increment,Wait);
fprintf(handles.s,'%s', OutputString);
推荐答案
有多个函数,称为fprintf,一个用于文件,一个用于串行对象,其他一些.您正在使用从fprintf了解文件的功能,但是将其与串行对象一起使用.检查正确的文档,可以通过doc serial/fprintf
There are multiple functions called fprintf, one for files, one for serial objects and some others. You are using functionally which you know from the fprintf for files, but you are using it with a serial object. Check the right documentation which can be accessed via doc serial/fprintf
这篇关于输入参数过多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!