How to assign user entered values(integers entered in an edit text box) to an already user entered string in a listbox of MATLAB GUI? . Your support would be very useful.

2 views (last 30 days)
Data Inputed by User: A String in the listbox of a GUI and 3 integer values in an edit text box of the same GUI. Every time the user should be entering a string and then 3 integer values (x,y & z coords). Now with the user entered 3 coordinates,I would like to plot the point and assign these values to the already entered string in the listbox. I face problems in assigning the three points to the string. Because as future scope, If I select the string in the listbox and click a delete button the corresponding point in the plot should get deleted. This whole process must function in a loop as every time the user would like to enter new strings and assign 3 coordinate values to it. I have been trying a lot but not able to achieve the output. Your help will be deeply appreciated.
matlablearner on 15 Jul 2014
Edited: matlablearner on 15 Jul 2014
I tried something similar to what you have mentioned but I am struck at creating the structure and accessing it. I have attached the snapshot of my code for your reference.

Sign in to comment.

Answers (2)

Alfonso Nieto-Castanon
Alfonso Nieto-Castanon on 15 Jul 2014
Let's say that h_list, and h_text, are the handles to your listbox and textbox, respectively (which you have already created). You could simply define the callback property of your textbox:
and then define this callback function to modify the strings within the listbox. Something along these lines:
function mycallbackfcn(h_list)
str = get(h_list,'string'); % current strings in listbox
val = get(h_list,'value'); % selected string in listbox
coords = get(gcbo,'string'); % text entered in textbox
str{val} = coords;

Brian B
Brian B on 16 Jul 2014
Edited: Brian B on 16 Jul 2014
You are creating a struct correctly. However, you should also get the handle to the point when you create it:
h = scatter3(...);
and save the handle with the structure:
node = struct(..., 'nodehandle', h);
From the syntax highlighting I can tell that node is a persistent or global or shared variable; furthermore, the xc field of node is a vector with the x-coordinates of all of the nodes. It will probably be easier to define a struct ARRAY (call it Nodes, for example) as a persistent variable, and to let each element of the struct array represent one node. (In this case, you would get xc as xc = str2double(...) and not append it to any list; just save the scalar xc in node). Then you would create node as you have done and append it to Nodes:
Nodes(end+1) = node;
When the user selects a point, search through Nodes to find which element of the struct array has the matching handle and remove it from the list.
Brian B
Brian B on 18 Jul 2014
Edited: Brian B on 18 Jul 2014
This would be easier if you plotted each point as a separate line.
case 'plotnode'
% Set Default View
az = wrapTo360(-37.5); el = 30; %limits for az 0...360 for el 0...90
view(handles.axes1,[az el]);
%Plot the points
hold on;
'MarkerFaceColor',[1 0 0]);
node=struct('nodenumber', [node.nodenum; nodenum],...
'xcoordinate', [node.xc; xc], ...
'ycoordinate', [node.yc; yc], ...
'zcoordinate', [node.zc; zc], ...
'nodehandle', [node.h; h]);
Before you delete the corresponding handle in node.h, delete the point:
case 'deletenode'
nnames = get(handles.nodeslistbox,'String');
if length(nnames)<1;
end; %if already empty, do nothing
index_selec = get(handles.nodeslistbox,'Value');
delete(node.h(index_selec)); % THIS IS THE KEY!
if val<1; val=1;end %take care of exception
Alternatively, you could remove the corresponding coordinates from node.xc etc and replot.

Sign in to comment.


Find more on Characters and Strings 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!