1

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.

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
user2868118
  • 43
  • 2
  • 9
  • thewaywewalk, the answer you provided works like magic. I am not sure what you are asking me to do. – user2868118 Jan 08 '14 at 05:46
  • But you couldn't change it to detect multiple patterns? - I'd like to help you more, but I don't have the time, and its not trivial, I would have to do try&error a lot as well. Let me know, if you finish this task sometime, I would be interested. Good luck! – Robert Seifert Jan 08 '14 at 10:15
  • For now I could only let the first column set incrementally and let the other columns set the same value when dragged. I only changed one or two things in your useful code. I tried making it work like in a conventional spreadsheet where you select two or more cells and drag but I got stuck. Anyway I will keep trying. Thanks so much, thewaywewalk. – user2868118 Jan 08 '14 at 20:28

2 Answers2

1

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.

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
  • Thank you for the post. It works in increasing order as you said. I will work around your code so that I can maintain the same value when dragged. But since it can be done done(even though a heavy task), I will try whether I can handle that and give you feedback. I am very grateful. Regards. – user2868118 Jan 02 '14 at 12:42
0

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.

Fraukje
  • 673
  • 3
  • 20