Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据附加到';对于';MatLab中的循环_Matlab_Messagebox_Matlab Guide_Matlab Uitable - Fatal编程技术网

将数据附加到';对于';MatLab中的循环

将数据附加到';对于';MatLab中的循环,matlab,messagebox,matlab-guide,matlab-uitable,Matlab,Messagebox,Matlab Guide,Matlab Uitable,我编写了一个函数,它使用用户输入在单元格数组的一列中查找壁橱值并返回其索引。我使用此索引打印该索引处的所有列值。然后通过消息框将其显示给用户 prompt2 = 'Enter the Luminance value in cd/m^2'; linp = inputdlg (prompt2,'Input Value',1); luser=str2double(linp); for ab=1:num_files files=char(fileloc(ab)); dev=

我编写了一个函数,它使用用户输入在单元格数组的一列中查找壁橱值并返回其索引。我使用此索引打印该索引处的所有列值。然后通过消息框将其显示给用户

 prompt2 = 'Enter the Luminance value in cd/m^2';
 linp = inputdlg (prompt2,'Input Value',1);
 luser=str2double(linp);

 for ab=1:num_files
     files=char(fileloc(ab));
     dev=dlmread(files);
     round_tmp=abs(dev(:,4)-luser);
     [val,ind]=min(round_tmp);
     display(ind);
     msgbox(sprintf(' Values at %0.3f cd/m^2 for \n %s are:- \n\n Voltage    %0.3f V\n Current den.   %0.3f mA/cm^2 \n Current    %0.3f mA \n Efficiency   %0.3f cd/A',luser,forlegend{ab},dev(ind,1),dev(ind,5),dev(ind,2),dev(ind,6)),'Resulting Values');
 end
现在,我在一个“for”循环中对几个文件重复这个过程,每次它都会弹出一个新的“消息框”,如下所示: 在单个消息框中显示所有数据的最简单方法是什么?我尝试将其存储在一个文件中并重新显示,这会使消息框标题混乱。我只想把所有数据一个接一个地放在一个消息框中。有什么建议吗


感谢您的帮助。

如果消息框中有很多行要显示,则
msgbox
似乎不是最佳解决方案,因为它没有滚动条,您只能看到部分行

在这种情况下,一个简单的解决方案是通过以下方式构建您自己的消息框:

  • 创建一个
  • 添加
    uicontrol编辑框
  • 添加一个OK
    按钮来关闭图形(通过按钮的“回调
然后在循环中,您可以:

  • 在每次迭代中生成字符串
  • 将其附加到上一个
  • 将字符串设置为
    uicontrol编辑框的
    string
    属性
您可以使用
guide
创建更复杂的GUI

此解决方案在以下代码中实现:

创建您的onw消息框

% Create the figure
f=figure('unit','normalized','name','MY-_MESSAGE-_BOX','numbertitle','off');
% Add an edit text box
my_msg_box=uicontrol('parent',f,'style','edit','max',3,'unit','normalized', ...
   'HorizontalAlignment','left','position',[.1 .1 .7 .7])
% Add the OK button and set its callback to close the figure
ok_bt=uicontrol('parent',f,'style','pushbutton','unit','normalized', ...
   'string','OK','position',[.85 .5 .1 .1],'callback','delete(f);clear f')
创建字符串并将其添加到编辑框中

% Create the figure
f=figure('unit','normalized','name','MY-_MESSAGE-_BOX','numbertitle','off');
% Add an edit text box
my_msg_box=uicontrol('parent',f,'style','edit','max',3,'unit','normalized', ...
   'HorizontalAlignment','left','position',[.1 .1 .7 .7])
% Add the OK button and set its callback to close the figure
ok_bt=uicontrol('parent',f,'style','pushbutton','unit','normalized', ...
   'string','OK','position',[.85 .5 .1 .1],'callback','delete(f);clear f')
编辑以使OP注释后的代码更加清晰

在下面的示例中,在每次迭代期间,都会生成要显示的字符串(为了测试代码,我已经用“数字”替换了变量
luser、dev(ind,1)、dev(ind,5)、dev(ind,2)、dev(ind,6)

基本上,您必须用
sprintf
调用来替换
msgbox
指令

关于
sprintf
调用的实现(恢复变量
luser、dev(ind,1)、dev(ind,5)、dev(ind,2)、dev(ind,6)
),您必须:

  • 添加
    %s
    作为第一个格式描述符
  • 添加
    str
    作为第一个输入参数
这将允许“附加”字符串

如果只有几行要显示,只需在循环的每次迭代中生成字符串并将其附加到上一次迭代,而无需调用
msgbox
函数

在循环结束时,您可以调用
msgbox
,并为其提供“完整”字符串

希望这有帮助


Qapla'

如果消息框中有很多行要显示,则
msgbox
看起来不是最佳解决方案,因为它没有滚动条,您只能看到部分行

在这种情况下,一个简单的解决方案是通过以下方式构建您自己的消息框:

  • 创建一个
  • 添加
    uicontrol编辑框
  • 添加一个OK
    按钮来关闭图形(通过按钮的“回调
然后在循环中,您可以:

  • 在每次迭代中生成字符串
  • 将其附加到上一个
  • 将字符串设置为
    uicontrol编辑框的
    string
    属性
您可以使用
guide
创建更复杂的GUI

此解决方案在以下代码中实现:

创建您的onw消息框

% Create the figure
f=figure('unit','normalized','name','MY-_MESSAGE-_BOX','numbertitle','off');
% Add an edit text box
my_msg_box=uicontrol('parent',f,'style','edit','max',3,'unit','normalized', ...
   'HorizontalAlignment','left','position',[.1 .1 .7 .7])
% Add the OK button and set its callback to close the figure
ok_bt=uicontrol('parent',f,'style','pushbutton','unit','normalized', ...
   'string','OK','position',[.85 .5 .1 .1],'callback','delete(f);clear f')
创建字符串并将其添加到编辑框中

% Create the figure
f=figure('unit','normalized','name','MY-_MESSAGE-_BOX','numbertitle','off');
% Add an edit text box
my_msg_box=uicontrol('parent',f,'style','edit','max',3,'unit','normalized', ...
   'HorizontalAlignment','left','position',[.1 .1 .7 .7])
% Add the OK button and set its callback to close the figure
ok_bt=uicontrol('parent',f,'style','pushbutton','unit','normalized', ...
   'string','OK','position',[.85 .5 .1 .1],'callback','delete(f);clear f')
编辑以使OP注释后的代码更加清晰

在下面的示例中,在每次迭代期间,都会生成要显示的字符串(为了测试代码,我已经用“数字”替换了变量
luser、dev(ind,1)、dev(ind,5)、dev(ind,2)、dev(ind,6)

基本上,您必须用
sprintf
调用来替换
msgbox
指令

关于
sprintf
调用的实现(恢复变量
luser、dev(ind,1)、dev(ind,5)、dev(ind,2)、dev(ind,6)
),您必须:

  • 添加
    %s
    作为第一个格式描述符
  • 添加
    str
    作为第一个输入参数
这将允许“附加”字符串

如果只有几行要显示,只需在循环的每次迭代中生成字符串并将其附加到上一次迭代,而无需调用
msgbox
函数

在循环结束时,您可以调用
msgbox
,并为其提供“完整”字符串

希望这有帮助


Qapla'

如果打印的字符串填充的区域大于消息框的区域,您是否可以链接一个图像,以显示消息框的外观?例如,
msgbox(sprintf('1\n2\n3\n4\n5…等等'))
如果打印的字符串填充的区域大于消息框的区域,您是否可以链接一个图像以显示消息框的外观?例如,
msgbox(sprintf('1\n2\n3\n4\n5…等等'))
谢谢,伙计。是的,我的数据超过了普通消息框的大小,所以我需要用滚动条创建一个图。我尝试了你的建议,创建一个图,并使用“将其与数据一起附加”。但是我的消息框只显示最后一条sprintf语句。它并不像你在示例中所示的那样进行附加。我正在尝试找出原因。你可以吗你认为这是为什么吗?我已经测试了我发布的代码,它可以正常工作。请检查你是否以正确的方式实现了它:在调用
sprintf
时“应用”你必须添加的字符串:a
%s
开头和
str<