MATLAB Answers

How to use the uimenu to assing value to variables

2 views (last 30 days)
Sadegh Salesi Mousaabadi
Sadegh Salesi Mousaabadi on 23 Jan 2017
Commented: Greg Heath on 28 Nov 2018
I am going to develop a neuron network topology in which the topology is layered (like a neural network). Due to plenty number of neurons, we cannot ask the user to assign value to each neuron model and type and the best option is to assume that all the neurons have the same type and model initially and wherever necessary the user to be able to change the each neuron type or model using a right-click option on the figure. The code below is a very simple topology of 8 neurons (2 inputs, 3 neurons in layer 1, 2 neurons in layer 2 and, 1 output neuron)
clc,clear
NoNeuron=8;
NoInNeuron=2;
NoOutNeuron=1;
NoLayers=2;
NoNeuronL1=3;
NoNeuronL2=2;
NoType=NoLayers+1+1;
emp.x=[];
emp.y=[];
emp.type=[];
emp.model=[];
Neuron=repmat(emp,NoNeuron,1);
x=[1;1;2;2;2;3;3;4];
y=[2;4;1;3;5;2;4;3];
hold on
line([1 2],[4 5])
line([1 2],[4 3])
line([1 2],[4 1])
line([1 2],[2 5])
line([1 2],[2 3])
line([1 2],[2 1])
line([2 3],[5 4])
line([2 3],[5 2])
line([2 3],[3 4])
line([2 3],[3 2])
line([2 3],[1 4])
line([2 3],[1 2])
line([3 4],[4 3])
line([3 4],[2 3])
net=plot(x,y,'mo','LineWidth',2,'MarkerSize',15,'MarkerEdgeColor','g','MarkerFaceColor','r');
axis([0,5,0,6])
c = uicontextmenu;
net.UIContextMenu = c;
topmenu = uimenu('Parent',c,'Label','Neuron Model');
topmenu1 = uimenu('Parent',c,'Label','Neuron Type');
m1 = uimenu('Parent',topmenu,'Label','Integrate and fire');
m2 = uimenu('Parent',topmenu,'Label','Leaky integrate and fire ');
m3 = uimenu('Parent',topmenu,'Label','Izhikevich');
t1 = uimenu('Parent',topmenu1,'Label','Type1');
t2 = uimenu('Parent',topmenu1,'Label','Type2');
t3 = uimenu('Parent',topmenu1,'Label','Type3');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
If you run this code the topology would be drawn. The neurons are structured to have x position, y position, type, and model. For this simple example, the value of x and y positions are entered manually. For right-click option, I used uimenu function so if you right-click on each neuron the options for neuron type and model would appear. What I want now is that whenever the user click on each neuron type (model) in the figure, its value is kept in the corresponding neuron type (model) in the main algorithm.
Anyone any suggestion?
I would appreciate your helps and suggestions
thanks

Answers (1)

Chirag Parekh
Chirag Parekh on 27 Jan 2017
Edited: Chirag Parekh on 27 Jan 2017
I did not get which value you want to save, but you can use callback functions to do such things.
t1 = uimenu('Parent',topmenu1,'Label','Type1', 'Callback',@myfunc);
%nyfunc.m
function myfunc(src,evt)
disp('In myfunc');
end

Community Treasure Hunt

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

Start Hunting!

Translated by