输入参数太多

2023-12-01

我收到以下有关 fprintf 函数中输入参数过多的错误消息。但在我看来,通过了适量的论点。

所有这些都是在我制作的 GUI 指南的背景下进行的(见最后的图片)。

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来自哪里

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

和 setupserial 函数

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

enter image description here


使用以下解决了问题

OutputString = sprintf('C0 %s %s %s %s',StartStepsStr,EndStepsStr,Increment,Wait);
fprintf(handles.s,'%s', OutputString);

有多种称为 fprintf 的函数,一种用于文件,一种用于串行对象,还有一些其他函数。您正在使用从 fprintf 中知道的文件功能,但您将其与串行对象一起使用。检查可以通过以下方式访问的正确文档doc serial/fprintf

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

输入参数太多 的相关文章

  • printf 似乎忽略了字符串精度

    所以 我有点难受 根据man 3 printf在我的系统上 字符串格式 5s 应使用指定的精度来限制从给定字符串参数打印的字符数 man 3 printf PRINTF 3 BSD Library Functions Manual PRIN
  • 如何以编程方式指定 MATLAB 编辑器键绑定

    我想将键盘键绑定设置为Windows 默认设置我想在启动时使用startup m因为我希望在大量系统上设置此设置 首选项对话框中的等效设置是 MATLAB gt Keyboard gt Shortcuts gt Active Setting
  • 傅里叶变换定理 matlab

    我目前正在尝试理解二维傅里叶位移定理 根据我到目前为止所了解到的情况 图像空间中的平移会导致相位差异 但不会导致频率空间中的幅度差异 我试图用一个小例子来演示这一点 但它只适用于行的移位 而不适用于列的移位 这是一个小演示 我只在这里显示幅
  • OCaml 中的用户定义打印机

    printf fprintf等 全部接受 a转换 手册上说对于 a 用户定义的打印机 采用两个参数 并将第一个参数应用于 outchan 当前输出通道 和第二个参数 因此 第一个参数的类型必须为 out channel gt b gt un
  • 频域和空间域的汉明滤波器

    我想通过在 MATLAB 中应用汉明滤波器来消除一维信号中的吉布斯伪影 我所拥有的是k1这是频域中的信号 我可以通过应用 DFT 来获取时域信号k1 s1 ifft ifftshift k1 该信号具有吉布斯伪影 现在 我想通过 A 乘以汉
  • Matlab Solve():未给出所有解决方案

    我试图找到两条曲线的交点 syms x y g x 20 exp x 30 3 5 1 sol x sol y solve x 22 3097 2 y 16 2497 2 25 y g x x y Real true 它只提供一种解决方案
  • MATLAB - GUI 和 OPC 服务器

    我想在 MATLAB 中设计一个图形用户界面 可以使用 MATLAB 的过程控制对象链接和嵌入 OPC 工具箱连续读取数据 我怎样才能实现这个 我已经设计了图形用户界面 但我无法将数据读入图形用户界面 就这样做 type opctoolMA
  • 垂直子图的单一颜色条

    我想让下面的 MATLAB 图有一个沿着两个子图延伸的颜色条 像这样的事情 使用图形编辑器手动完成 Note 这与提出的问题不同here https stackoverflow com questions 39950229 matlab t
  • C++ 的 String.Format

    正在寻找 NET 的 String Format 等函数的 C 实现 显然有 printf 及其变体 但我正在寻找具有位置的东西 如下所示 String Format 您好 0 您是 1 岁 感觉如何 1 姓名 年龄 这是必要的 因为我们将
  • 从筛查乳腺 X 光检查数字数据库 (DDSM) 获取数据

    我正在尝试以可读格式获取 DDSM 数据集 有谁有 DDSM heathusf 程序的工作版本 可以在 Linux 或 Windows 上正常运行吗 我知道 DDSM 的 jpeg 程序有一个适用于 linux 的工作版本 位于http w
  • java中%%是什么意思?

    我是一名 PHP 程序员 想知道这行代码的含义 System out printf exp 3f is 3f n x Math exp x 3f 3f n 和逗号 x 是什么意思 它与C类似printf http java sun com
  • Java:将二维字符串数组打印为右对齐表格

    是什么best打印a的单元格的方法String 数组作为右对齐表 例如 输入 x xxx yyy y zz zz 应该产生输出 x xxx yyy y zz zz 这似乎是一个should能够完成使用java util Formatter
  • 直方图均衡结果

    I am trying to code histogram equalization by my self but the results are different from the built in function in matlab
  • 在 Matlab 的命令窗口中获取旧式帮助

    问题的简短版本 在最新版本的 Matlab 中 我在 Windows 上的 R2014b 和 R2015a 中看到过 当您键入help foo你得到一个简要描述 简介函数及其签名 例如 输入help bsxfun产生类似这样的东西 只有更好
  • Python 或 C 语言中的 Matlab / Octave bwdist()

    有谁知道 Matlab Octave bwdist 函数的 Python 替代品 此函数返回给定矩阵的每个单元格到最近的非零单元格的欧几里得距离 我看到了一个 Octave C 实现 一个纯 Matlab 实现 我想知道是否有人必须用 AN
  • 在 matlab 代码中使用 dll 文件

    我需要使用 Matlab 中由 dll 文件定义的函数 我有一个例子 那个家伙将 dll 转换为 mexw32 文件 但我知道我是如何做到这一点的 我尝试使用加载库但它没有创建任何文件 我怎样才能做到这一点 loadlibrary http
  • 从 MATLAB 调用 Java?

    我想要Matlab程序调用java文件 最好有一个例子 需要考虑三种情况 Java 内置库 也就是说 任何描述的here http docs oracle com javase 6 docs api 这些项目可以直接调用 例如 map ja
  • 如何使用 sprintf 函数在字符中添加前导“0”而不是空格?

    我正在尝试使用sprintf函数为字符添加前导 0 并使所有字符长度相同 然而我得到的是领先空间 My code a lt c 12 123 1234 sprintf 04s a 1 12 123 1234 我试图得到什么 1 0012 0
  • for 循环中的绘图没有可见点

    我正在努力解决我想使用 for 循环制作的情节 我知道当我在循环之后添加它时它会起作用 只是一个简单的图 但我想用另一种方式尝试一下 fib ones 1 10 for k 3 10 hold on fib k fib k 1 fib k
  • Numpy 相当于 MATLAB 的 hist [重复]

    这个问题在这里已经有答案了 由于某种原因 Numpy 的 hist 总是返回比 MATLAB 的 hist 少 1 个 bin 例如在 MATLAB 中 x 1 2 2 2 1 4 4 2 3 3 3 3 Rep Val hist x un

随机推荐