How to delete a cell in gui

5 views (last 30 days)
Hi, I want to delete a line from a plot in GUI. To do that, I have created the following code:
line1=num2str(get(handles.plotHandles,'XData'));
delete(line1)
where line1 is composed of 2x1 cells = [ 1x2 double]
[1x2 double]
it seems something is wrong here but I cannot find the solution. I am getting the following error:
Any suggestion to fix this error?
Undefined function 'abs' for input arguments of type 'cell'.
Error in num2str (line 66)
xmax = double(max(abs(widthCopy(:))));
Error in Loading_Well_logs>pushbutton8_Callback (line 1931)
line1=num2str(get(handles.plotHandles,'XData'));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Loading_Well_logs (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Loading_Well_logs('pushbutton8_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback

Accepted Answer

Walter Roberson
Walter Roberson on 19 Feb 2020
When you get() a property from more than one graphic object, you get back a cell array in response. You are trying to use num2str on that cell, but cell cannot be converted to characters by num2str.
The Xdata associated with a line plot is the X coordinates in data units. You are taking the data units and trying to convert the coordinates to characters. Then you pass the characters to delete(). When you pass characters to delete() that is interpreted as a request to delete a file named by the characters.
If you want to remove graphics objects from display and memory
delete(handles.plothandles)

More Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!