0

Question 1

I wrote a gui code that gives the following row which is then made to display on a uitable:

combt =

Columns 1 through 5

2000    2530.4    2671.4    2.3   2.6

This row will be automatically added to row 1 in the uitable:

See here In my example above, I would like this row to be added to row 2000 (depending on column 1 of my data).

Therefore if my row has a column_1 = 10, I would like this row to appear at row 10 in the uitable and so on. I have been looking for this answer for over a year so your help will be much appreciated.

Question 2:

Say I have a table with the following numbers

combt =

Columns 1 through 5

1    2630.4    2671.4    5.3   2.6
2    2530.2    2673.4    2.2   6.6
10   2331.4    4671.2    4.3   2.7
11   2550.4    6671.4    2.1   2.8

How can rearrange them so that ,again, column 1 corresponds to the row number and the spaces are filled with zeros as such:

combt =

Columns 1 through 5

1    2630.4    2671.4    5.3   2.6
2    2530.2    2673.4    2.2   6.6
0    0         0         0     0       (This is row 3)
0    0         0         0     0       (This is row 4)
0    0         0         0     0       (This is row 5)
0    0         0         0     0       (This is row 6)
0    0         0         0     0       (This is row 7)
0    0         0         0     0       (This is row 8)
0    0         0         0     0       (This is row 9)
10   2331.4    4671.2    4.3   2.7
11   2550.4    6671.4    2.1   2.8
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Mosawi
  • 197
  • 2
  • 16

1 Answers1

1

Use new_d(d(:,1),:)=d to create your new required matrix new_d. Here is a sample code.

d = [1    2630.4    2671.4    5.3   2.6; ...
2    2530.2    2673.4    2.2   6.6; ...
10   2331.4    4671.2    4.3   2.7; ...
11   2550.4    6671.4    2.1   2.8];

new_d(d(:,1),:)=d;

% with first column
f = figure();
t = uitable(f,'Data',new_d);

% without showing first column
f1 = figure();
t1 = uitable(f1,'Data',new_d(:,2:end));

Update uitable with new data :

%% update table
% new data containing same first column value 10 and 2 
d1 = [14    2630.4    2671.4    5.3   2.6; ...   
18    2530.2    2673.4    2.2   6.6; ...
10   3333.4    2671.2    3.3   1.7; ...
2   2331.4    4671.2    4.3   2.7];

% update data 
new_d(d1(:,1),:)=d1;

% update uitable with first column
set(t,'Data',new_d);

% update uitable without showing first column
set(t1,'Data',new_d(:,2:end));
Rijul Sudhir
  • 2,064
  • 1
  • 15
  • 19
  • Thank you. Is it possible to amend this table, i.e. if I acquire more rows, I would like to add them to the existing table. Also, I would like the acquired rows with the the same value in column 1 to overwrite the old ones. – Mosawi Jun 11 '16 at 20:09
  • Thank you, but this is still overwriting everything, producing a fresh table – Mosawi Jun 12 '16 at 20:45