what Is the proper way to send data from App Designer to functions in the regular work space?

6 visualizaciones (últimos 30 días)
I am working on an app that generates output files by calling already existing functions. So my work is simply compiling the code with a nice interface for inputs. I am extremely confused on the concept of properties and I do not understand how to refer to the variables outside the app and in the regular functions so I can use their values. I know that in the app I can create public properties then get their value with app.X . however, the only way I got my code to somewhat work is to forgo app. notation. I've been trying to just directly pass variables into the function using its input like the example below but this doesn't seem to work.
[coords,elems] = csh_maker(Ca_Si_ratio,base_structure)
here is some of the app code
properties (Access = public)
VMD_path
coords
elems
base_structure
Ca_Si_ratio % already defined as property error?
% Description
end
function VMDPathMenuSelected(app, event)
% creates input window for VMD path
prompt = {'Enter Path to VMD:'};
title = 'VMD Path';
dimensions = [1 70]; % adjusts size of input box
app.VMD_path = char(inputdlg(prompt,title,dimensions));
end
% Button pushed function: viewvmd
function viewvmdPushed(app, event)
fTest = fullfile(pwd, 'TEST.xyz');
cmd = [app.VMD_path ' ' fTest];
system(cmd)
end
% Button pushed function: CreateDataButton
function CreateDataButtonPushed(app, event)
Ca_Si_ratio = app.Ca_Si_ratio.Value;
base_structure = app.base_structure;
[app.coords,app.elems] = csh_maker(Ca_Si_ratio,base_structure);
write_vmd(app.coords,app.elems,'TEST.xyz');
% Value changed function: base_structure1
function base_structure1ValueChanged(app, event)
app.base_structure1 = app.base_structure1.Value
% choosing which file to use when generating output data
if strcmp(app.base_structure1,'Hamids 11 Ang. Tobermorite')
set(app.Ca_Si_ratio,'enable','on')
app.base_structure = 'TB11.txt'
elseif strcmp(app.base_structure1,'9 Ang. Tobermorite')
set(app.Ca_Si_ratio,'enable','off')
app.base_structure = '9A tob'
elseif strcmp(app.base_structure1,'Merlinos 11 Ang. Tobermorite')
set(app.Ca_Si_ratio,'enable','off')
app.base_structure = '11A - Merlino.lammps05'
elseif strcmp(app.base_structure1,'14 Ang. Tobermorite')
set(app.Ca_Si_ratio,'enable','off')
app.base_structure = '14A tob'
elseif strcmp(app.base_structure1,'Portlandite')
set(app.Ca_Si_ratio,'enable','off')
app.base_structure = 'Portlandite'
end
end
One of my inputs is used in a function that is later called inside the main function, so it would be nice if I could initially use the input in its origin so I wouldn't have to pass the input through multiple functions. I am a matlab newbie so any help would be appreciated! thank you!

Respuestas (1)

Ajay Kumar
Ajay Kumar el 3 de Oct. de 2019
doc assignin

Community Treasure Hunt

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

Start Hunting!

Translated by