Domanda

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.

È stato utile?

Soluzione

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:

enter image description here

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


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.

All in all it is a heavy task, I'm not sure if it's worth it. But it can be done.

Altri suggerimenti

In uitable you insert data (usually a matrix) to be displayed in a table. So unlike Excel the uitable function is merely a form of displaying your data instead of a tool to manipulate it. See for more information here. However, if you want to set up a row for instance running from 1 until 10 you could use the following steps:

So say one would like to display a matrix of size 10x10, e.g. A=magic(10);

You can now set up a table t to display this matrix by

t=uitable('Data',A);

In your case if you want a row to be, e.g., 1 till 10, just change the matrix A containing your data to hold this row using

A(1,1:10)=1:10;

And re-execute the former command to bring up your table t.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top