I'm creating a Nx3 uitable since it seems much easier than multiple text-edits when N is high. I initialised the columns as cell array in order to initially obtain an 'empty' table.
hinitial = cell(N,1);
hfinal = cell(N,1);
hporosity = cell(N,1);
DataInput = [hinitial;hfinal;hporosity];
ColumnName = {'n_Initial','n_Final','Porosity'};
ColumnFormat = {'numeric', 'numeric', 'numeric'};
ColumnEditable = [false true false];
htable = uitable(fig,'Units','pixels','Position',[20 20 260 204],...
'Data', DataInput,...
'ColumnName', ColumnName,...
'ColumnEditable', ColumnEditable);
1) With this pushbutton I want to loop-print the data into the first column.
function uploadbutton_Callback(source,eventdata)
S = load('n.mat');
for K = 1:N
set(htable(K,1),'Data',num2cell(S.n(K)));
end
end
But this does the printing only for the first row of that column. Then this error is displayed.
Index exceeds matrix dimensions.
Error in bandprovaprog/uploadbutton_Callback (line 122)
set(htable(K,1),'Data',num2cell(S.n(K)));
Error while evaluating UIControl Callback.
2) In the second column I want to manually input data, then save the results in a mat file using a pushbutton. My effort so far is this:
function donebutton_Callback(source,eventdata)
m = zeros(1,N);
for J = 1:N
m(J) = str2double(get(hfinal{J},'String'));
end
save('m.mat','m');
end
3) Last column again uses set to print in the third column so I think I can do it once I know how to do 1)
EDIT2: edit of donebutton_Callback
function donebutton_Callback(source,eventdata)
m = zeros(1,N);
m(1:N) = str2double(htable.Data(1:N,2),'Data');
save('m.mat','m');
end
I want to put the content of the second column into m.mat
