在 MATLAB GUI 标签中使用空格时出错

Error using whitespace in MATLAB GUI label

我正在写一个包含弹出菜单的图形用户界面。此弹出菜单应根据名为 titles 的单元格数组显示不同的名称,如下所示:

handles.titles={'time','velocity','angular velocity'};

接下来,当我单击弹出菜单时,我希望它绘制连接到该标题的列。

所以如果我点击第二个弹出菜单选项,我想获得速度与时间的关系图。

handles.Parameter_Menu=hObject;
axes(handles.low_axis);
guidata(hObject,handles)
x_axis=xlim([handles.top_axis]);
set(hObject,'string',handles.titles(1:size(handles.matrix.Data,2)));
channel = get(hObject,'Value');
title_channel=handles.titles{channel}

plot(handles.(handles.titles{1}),handles.(handles.titles{channel}));
text=['graph of ' handles.titles2{channel} ' vs ' handles.titles2{1}];
title(text,'fontsize',12)
set(gca,'fontsize',10)
grid on

当我尝试使用 title{3} 时出现问题,因为它在单词之间有一个 space。

当然我可以这样写 angular_velocity 但是当我在图表的标题中使用它时,我收到的字母 "v" 很小,因为它前面有 _。

是否有任何选项可以使其与 space 一起使用,或者是否可以选择与 _ 一起使用但避免其在标题中的影响?

为了让图中的标题准确显示_,可以在_之前插入\(类似于latex):

handles.titles={'time','velocity','angular\_velocity'};

更新:

既然你不仅要用titles{i}来作图,还要在其他命令中把它作为struct的fieldname,那么没办法space,因为struct的fieldname必须满足一些条件:Valid field names begin with a letter, and can contain letters, digits, and underscores.

所以,必须使用titles{3} = 'angular_velocity'才能使其他操作正常,并且将标题的Interpreter属性设置为none才能使剧情的标题显示as typed(默认为 TeX 标记,这就是为什么我在上面的 _ 中使用 \_):

title(handle_of_something, titles{3}, 'Interpreter','none')