Problem while creating a gui and to share variables via assignin
Afficher commentaires plus anciens
Hello,
I just created a gui where I'm facing a problem. Let me explain it briefly.
First, the Import button is pressed. Then a csv is read in. So that I have the imported data available in the workspace, I transfer it in the callback function with assignin to the workspace.
The variables can also be found in the workspace. Unfortunately I cannot pass them to other functions. In the appendix I have added a short minimal example in which the problem can be reproduced.
Thanks a lot for your help
clear all
fig = uifigure;
fig.Position(3:4) = [600 320];
ax = uiaxes('Parent',fig,...
'Units','pixels',...
'Position',[10 10 300 280]);
btn = uibutton(fig,...
'push',...
'Position',[400,215, 100, 22],...
'Text','Plot',...
'BackgroundColor',[0.3010 0.7450 0.20],...
'ButtonPushedFcn', @(btn,event)...
plotButtonPushed(btn,ax,...
variable_1));
% when this button is pressed, this function should get the created
% variable from the callback function
import = uibutton(fig,...
'push',...
'Position',[100,290, 100, 22],...
'Text','Import',...
'BackgroundColor',[0 0.8 0.6],...
'ButtonPushedFcn', @(btn,event) plotButtonImport(fig));
function plotButtonImport(fig)
assignin('base','variable_1',10)
% Here I create a variable and give it to the base workspace
end
function plotButtonPushed(btn,ax,value)
k=k+1;
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Update figure-Based Apps dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!