GUI 'uitable' with option to add rows using push button for string

Hi, Guys, I want to add a string to new rows in Uitable Matlab but have errors
if true
data = get(handles.uitable, 'data');
if iscell(data); data = cell2mat(data); end
data(end+1,:) = ['june' ,12];
set(handles.uitable, 'data', data);

Answers (1)

Emir - without knowing the errors, we can only guess at the problem given the code that you have posted. I do suspect there is an error with
data(end+1,:) = ['june' ,12];
Note that you are trying to assign an array that has a string and number to the data matrix...which you had converted from a cell array. That conversion might have caused an error too if the cell array is composed of strings (for the months) and numbers (for the day). I suggest that you leave the uitable data as a cell array and then just append the new data to it
data = get(handles.uitable, 'data');
data = [data ; {'june' 12}];
Try that and see what happens!

4 Comments

yes- my purpose and my code is
if true
[filename, pathname] = uigetfile('*.m', 'Select a MATLAB code file', ...
'MultiSelect', 'on');
if isequal(filename, 0)
disp('User selected Cancel')
return;
end
x=handles.x
x=x+1;
filename = cellstr(filename); % Care for the correct type
k=handles.n;
guidata(hObject, handles);
disp(k);
for k = 1:length(filename)
disp(fullfile(pathname, filename{k}))
d(end+1,:) = {filename{k},x};
set(handles.uitable,'Data',d);
handles.n=handles.n+k;
guidata(hObject, handles);
end
end
Emir - what is d in your above code? A matrix or cell array? Please clarify what the issue or error is.
I am new in Matlab d is a matrix -my error is this : can't go to End of the matrix array with end+1
if true
Undefined function or variable 'd'.
Error in example>browser_Callback (line 94) d(end+1,:) = {filename{k},x};
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in example (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)example('browser_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback end
Emir - try concatenating instead...if d is a cell array
d = [d ; {filename{k},x}];

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Asked:

on 24 May 2018

Commented:

on 26 May 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!