通过用户输入生成MATLAB uitable行 [英] MATLAB uitable row generation from user input

查看:495
本文介绍了通过用户输入生成MATLAB uitable行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中有一个GUI,该GUI使用 UIables 输入.有固定数目的列,每列都有一种非常特定的格式,我将其存储为单元格数组,如下所示:

I've got a GUI in MATLAB which uses uitables for input. There are a fixed number columns, and each column has a very specific format which I have stored as a cell array, like so:

columnformat = {'text', 'numeric', {@doSomething, inputArg1}, {'Option1' 'Option2'}};

理论上行数不受限制;用户可以提供任意数量的内容.后端能够任意处理许多行输入.现在,我最初是在构建一个大型的uitable,只是假设用户不会全部使用它.

The number of rows is theoretically unlimited; the user could provide as many they like. The back-end is capable of handling arbitrarily many row inputs. Right now, I'm building a large uitable initially, and just assuming the user won't use it all.

这里的问题是:我想设置表和相关代码,以便用户每次选择最后一行并按Enter时,它都会以与表其余部分相同的格式创建新行.

Here's the question: I want to set up the table and associated code such that any time the user has selected the final row and presses enter, it creates a new row with the same format as the rest of the table.

我尝试了许多不同的方法,包括动态设置数据",它们似乎都破坏了单元格数组所要求的自定义格式.我敢肯定有人这样做过.感谢您的帮助!

I've tried many different approaches, including dynamically setting 'Data', and they all seem to break the custom formatting dictated by the cell array. I'm sure someone has done this before. Thanks for your help!

推荐答案

我想不出用某个键来实现您想要的功能的可能性,我想用任何键(KeyPressFcn)都可以实现.但我宁愿建议您使用带有按钮的工具栏:

I couldn't think of a possibility to achieve what you want with a certain key, I think it would be possible with any key (KeyPressFcn). But I'd rather recommend to introduce a toolbar with a pushbutton:

h = figure(...
u = uitable(h, ...
set(u,'Tag','myTable')
tbar = uitoolbar(h);
uipushtool(tbar,'ClickedCallback',@addRow);

在回调函数中,您需要获取数据,添加一行并将其写回:

In your callback function then you need to get your data, add a row and write it back:

function addRow(~,~)

u = findobj(0,'Type','uitable','Tag','myTable');
data = get(u,'Data');
%// modify your data, add a row ...
set(src,'Data',data);

end

很抱歉,如果一切都有些简单且未经测试,但是好的答案将需要大量的精力,我没有时间.标签可以给出您还有很多其他想法.

Sorry if everything is a little simple and untested, but a good answer would require a considerable effort, I don't have time for. The tag matlab-uitable can give you a lot of further ideas.

这篇关于通过用户输入生成MATLAB uitable行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆