Concatenating Edit Field value with an existing string in App Designer

24 visualizaciones (últimos 30 días)
NOTE: Bare with me--I am new to MATLAB so my "code talk" might be a little off.
I am trying to equal the value of a variable in my string to the value of an Edit Field in my app. In order to do this I believe I must turn my Edit Field value into a string and then contatenate it to my existing string, but what I have right now gives me a massive error. Help!
Additional info:
-The existing string describes a set of equations needed to plot a graph (so the ultimate goal is to have the graph update whenever the Edit field value changes).
-Eventually I need to connect edit fields to every variable (gNA, gK, gLeak, eNa, eK, eL, i) but I am only working on the first one (gNA) for now.
-This code uses DynaSim
Here is what I have so far:
app.gNaValue = app.gNaEditField.Value; %app.gNaValue is a Property I created to hold the value of the edit field
eqns={
% Variables:
strcat('gNa=',string(app.gNaValue),';') % THIS IS THE LINE THAT I AM WORKING ON
'gK=36;'
'Cm=1;'
'gLeak=.3;'
'eNa=115;'
'eK=-12;'
'eL=10.6;'
'i=10'
%Equations
'INa(v,m,h) = gNa.*m.^3.*h.*(v-eNa)'
'IK(v,n) = gK.*n.^4.*(v-eK)'
'dv/dt = (x(t)-INa(v,m,h)-IK(v,n)-(gLeak.*(v-eL)))/Cm; v(0)=0; v0=0'
'x(t)=i*(t>0)+-i*(t>1000)'
'dm/dt = aM(v).*(1-m)-bM(v).*m; m(0)=.1'
'dh/dt = aH(v).*(1-h)-bH(v).*h; h(0)=.1'
'dn/dt = aN(v).*(1-n)-bN(v).*n; n(0)=0'
'aM(v) = (2.5-.1*(v-v0))./(exp(2.5-.1*(v-v0))-1)'
'bM(v) = 4*exp(-(v-v0)/18)'
'aH(v) = .07*exp(-(v-v0)/20)'
'bH(v) = 1./(exp(3-.1*(v-v0))+1)'
'aN(v) = (.1-.01*(v-v0))./(exp(1-.1*(v-v0))-1)'
'bN(v) = .125*exp(-(v-v0)/80)'
};
data=dsSimulate(eqns,'tspan',[0 1000]); % telling dynasim to simulate the eqns [time change = ,'tspan',[0 1000]]
plot(app.HodgkinHuxlleyNeuronGraph,[data.time],[data.(data.labels{1})]);axis(app.HodgkinHuxlleyNeuronGraph,[900 1000 -20 100]); % calling upon data.time and data.labels to create a plot
Any help would be appreciated. Thanks!
  1 comentario
Sabina Vitola
Sabina Vitola el 2 de Ag. de 2022
Here is the error I got:
Index exceeds the number of array elements. Index must not exceed 0.
Error in dsCheckSpecification (line 536)
sz=cellfun(@str2double,regexp(tmp{1},',','split'));
Error in dsGenerateModel (line 161)
specification = dsCheckSpecification(specification, varargin{:}); % standardize & auto-populate as needed
Error in dsCheckModel (line 106)
model = dsGenerateModel(model, 'stvar_alias_flag', options.stvar_alias_flag);
Error in dsSimulate (line 546)
model = dsCheckModel(model, varargin{:}); % handles conversion when input is a string w/ equations or a DynaSim specification structure
Error in Neur_act_GUI/PlotButtonPushed (line 120)
data=dsSimulate(eqns,'tspan',[0 1000]); % telling dynasim to simulate the eqns [time change = ,'tspan',[0 1000]]
Error while evaluating Button PrivateButtonPushedFcn.

Iniciar sesión para comentar.

Respuestas (1)

Les Beckham
Les Beckham el 2 de Ag. de 2022
Editada: Les Beckham el 2 de Ag. de 2022
First, if you are getting an error, that is usually what will help you (and us) figure out what is wrong so, please, post the complete text of the error message (everything in red).
I believe that the contents of App Designer edit fields are already character vectors (which are not the same as strings). Single quotes create character vectors and the string function creates a string. When you strcat a character vector with a string you get a string. I don't know if your dsSimulate() tool will understand a cell array containing a mix of character vectors and strings.
I would suggest using sprintf instead of strcat:
sprintf('gNa=%s', app.gNaValue)
This will give you a character vector like the rest of your eqns cell array
  2 comentarios
Sabina Vitola
Sabina Vitola el 2 de Ag. de 2022
Thank you for the suggestion! I tried that and I am still getting the same error ( I just posted the error under my original question ). I understand where I was mixing up the character vectors and the strings so I will keep working in that direction.
Les Beckham
Les Beckham el 3 de Ag. de 2022
I would suggest entering this command at the command line before you run your code.
dbstop if error
This will cause Matlab to stop in the debugger where the error occurs. Then either use the Workspace explorer window or type whos tmp to find out the size of the variable tmp. It appears that it is empty (zero size). You should be able to click on the various red error messages to switch the debugger context to the various calling functions and examine the variables in those to find out where the input data is getting lost.
You can also set breakpoints in the code to stop the debugger at specific points in specific functions and step through the code, examining variables as you go to see where things are getting messed up.
Good luck.

Iniciar sesión para comentar.

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by