MATLAB Answers

Share variables between two popup menu? please help.

2 views (last 30 days)
shalaw faraj
shalaw faraj on 6 Feb 2015
Answered: Jason Moore on 6 Feb 2015
i have a question please help me? i have two popup menu, i share a variables between them but in one of them popup menu a variable doesn't declare, how can declare a variable that can use between them? completely i mean how can declare variable X and use between them ? ---------------
function popupmenu1_Callback(hObject, eventdata, handles)
str=get(hObject,'String');
val=get(hObject,'Value');
RGBimage=imread('C:\Users\Best Technology\Pictures\Camera Roll\WIN_20141029_092813.jpg');
[height,width,depth]=size(RGBimage);
switch str{val} ;
case 'Load'
axes(handles.axes1);
i=imread('C:\Users\Best Technology\Pictures\Camera Roll\WIN_20141029_092813.jpg');
imshow(i);
case 'Red'
axes(handles.axes2);
outputimage=uint8(zeros(height,width,depth));
for w=1:width
for h=1:height
outputimage(h,w,x)=RGBimage(h,w,x);
end
end
image(outputimage);
case 'Green'
axes(handles.axes2);
outputimage=uint8(zeros(height,width,depth));
for w=1:width
for h=1:height
outputimage(h,w,x)=RGBimage(h,w,x);
end
end
image(outputimage);
case 'Blue'
axes(handles.axes2);
outputimage=uint8(zeros(height,width,depth));
for w=1:width
for h=1:height
outputimage(h,w,x)=RGBimage(h,w,x);
end
end
image(outputimage);
end
--------------------
function popupmenu2_Callback(hObject, eventdata, handles)
str=get(hObject,'String');
val=get(hObject,'Value');
switch str{val} ;
case 'One'
x=1;
case 'Two'
x=2;
case 'Three'
x=3;
end

  0 Comments

Sign in to comment.

Answers (1)

Jason Moore
Jason Moore on 6 Feb 2015
Without knowing your code structure it is hard to give you the best answer possible. But an option that would work could be to use assignin and eval. assignin will take a value and assign it to the specified value in the specified workspace. eval will run a given command in the specified workspace.
Example
%write a value of 1 to x in the base workspace
assignin('base','x',1)
%read the value of x that is stored in the base workspace
val = eval('base','x')
By using this method the data will be viewable in your base workspace.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags