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

1 view (last 30 days)
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)
Ca_Si_ratio % already defined as property error?
% Description
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));
% Button pushed function: viewvmd
function viewvmdPushed(app, event)
fTest = fullfile(pwd, 'TEST.xyz');
cmd = [app.VMD_path ' ' fTest];
% 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);
% 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')
app.base_structure = 'TB11.txt'
elseif strcmp(app.base_structure1,'9 Ang. Tobermorite')
app.base_structure = '9A tob'
elseif strcmp(app.base_structure1,'Merlinos 11 Ang. Tobermorite')
app.base_structure = '11A - Merlino.lammps05'
elseif strcmp(app.base_structure1,'14 Ang. Tobermorite')
app.base_structure = '14A tob'
elseif strcmp(app.base_structure1,'Portlandite')
app.base_structure = 'Portlandite'
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!

Answers (1)

Ajay Kumar
Ajay Kumar on 3 Oct 2019
doc assignin


Find more on Scope Variables and Generate Names in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!