Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Share variables between two popup menu? please help.

1 Ansicht (letzte 30 Tage)
shalaw faraj
shalaw faraj am 6 Feb. 2015
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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

Antworten (1)

Jason Moore
Jason Moore am 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.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by