可在Matlab中拖动模式 [英] Drag pattern in uitable matlab

查看:239
本文介绍了可在Matlab中拖动模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在matlab uitable中拖动模式值.在电子表格中,要输入1到50的值,您需要输入1,2,3并选择单元格并拖动.请问这可以在MATLAB uitable中完成吗?问候.

I want to know if it is possible to drag pattern values in matlab uitable. In a spreadsheet, to enter values from 1 to 50, you need to enter 1,2,3 and select the cells and drag. Please can this be done in matlab uitable? Regards.

推荐答案

可以完成.但是不如使用excel舒服.

It can be done. But not as far as comfortable as with excel.

尝试以下代码,您可以尝试对其进行改进或根据需要进行更改.我认为这对您来说是一个很好的起点.

Play around a bit with the following code, you can try to improve it or change it to your needs. I think it is a good starting point for you.

function fancyTable 

defaultData = randi(99,25,2);

h = figure('Position',[300 100 402 455],'numbertitle','off','MenuBar','none');
uitable(h,'Units','normalized','Position',[0 0 1 1],...
              'Data', defaultData,... 
              'Tag','myTable',...
              'ColumnName', [],'RowName',[],...
              'ColumnWidth', {200 200},...
              'CellSelectionCallback',@cellSelect);
end

function cellSelect(src,evt)
try
index = evt.Indices;
data = get(src,'Data');
L = size(index,1);
rows = index(:,1);
column = index(1,2);
start = data(rows(1),column);
newdata = start:(start+L-1);
data(rows,column) = newdata';
set(src,'Data',data);
end
end

它创建一个包含两列的表:

It creates a table with two columns:

您可以选择数据,并根据第一个值立即应用所需的拖动模式.

You can select data and your desired drag pattern is applied immediately according to the first value.

该代码只是根据相应的值在选择的第一点插入一系列递增的值. 最困难的部分是检测模式!我刚刚评估了第一个数据值start = data(rows(1),column);,您可能还需要最少选择3:start = data(rows(1:3),column);.您可能需要使用许多try/catch结构来跳过所有无法解释的情况.或者您从一开始就使用switch/case结构来评估所选内容的长度并评估图案.

The code is just to insert an increasing series of values at the first point of selection based on the according value. The hardest part will be to detect the pattern! I just evaluated the first data value start = data(rows(1),column); you could also require a minimal selection of 3: start = data(rows(1:3),column);. You probably need to work with a lot of try/catch structures to skip all unexplained cases. Or you use switch/case structures from the beginning to evaluate the length of the selection and evaluate the pattern.

总而言之,这是一项艰巨的任务,我不确定是否值得.但这是可以做到的.

这篇关于可在Matlab中拖动模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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