why evalin doesnt wotk in App Designer matlab 2017b?

I am creating app in appdesginer .
When I ran the same code in same matlab version , it works but when I tried to implement it in app designer it gives error as
Undefined function or variable 'XXXX'.
What could be the reason or what could be the alternative for the same?

9 Comments

DGM
DGM on 1 Nov 2021
Edited: DGM on 1 Nov 2021
Considering that I don't know what you tried to execute or what was in whatever scope you tried to execute it in -- or how you tested it prior to this, I don't know. I am going to guess that the issue is possibly because you're not executing it in the same scope as when you were testing it. You will need to provide more information.
Also, you shouldn't be using evalin anyway.
@Rik Thanks for the comment. Not evelin then what should I use ? here is the code,
signalsize = NaN(length(list_signalnames),1);
for i_ctrl = 1:length(list_signalnames)
try
signalsize(i_ctrl)=evalin('base',['length(',list_signalnames{i_ctrl},');']);
catch
signalsize(i_ctrl) = NaN;
end
end
  • list_signalnames is 1X4 cell having these elements : 'PEM_SPEED_HD' 'APP_isc_n_gbxInp' 'TCU_DT2_APP_isc_n_gbxInp' 'n_bench_inp'
  • When I run this code in normal matlab this works fine but when I run it in appdesigner it gives following error although all inpouts are same -->
Error using evalin
Undefined function or variable 'APP_isc_n_gbxInp'.
I hope you have understood the issue
@DGM Hey Thanks for the commnet, I have explained the isse in above comment setion.
"Not evelin then what should I use ?"
Processing the data within the GUI is much better.
If required, use the debugging tools to view the data within the GUI.
I debugged it although all inputs and fucntions are same still it wont work in appdesginer. The only question is 'why eveli doesn't work in appdesigner' and 'what could be alternative for the same'?
Pass your variables as input arguments:
%you're doing this
a=1;
MyFun
function MyFun
a=evalin('base','a');
disp(a)
end
%you should do this
a=1;
MyFun(a)
function MyFun(a)
disp(a)
end
@Rik WHat is MyFun, what consist of it ?
That was just an example function. Since you haven't explained anything about how you call your function I can't actually suggest the real changes you should make. You shouldn't be needing evalin. You should use input arguments to your functions.
If you don't know how to do that I suggest you do a basic Matlab tutorial.

Sign in to comment.

 Accepted Answer

You probably forget to populate APP_isc_n_gbxInp in the base workspace.
I create a small app (attached) and evalin works just fine (R2021b)
>> clear
>> testevalin
Cannot retrieve a from base workspace % message when I click on "Get a button", not working since a is not created
>> a=1
a =
1
a = 1.000000 % message when I click on "Get a button", it woeks
>>

More Answers (0)

Categories

Products

Release

R2017b

Asked:

on 1 Nov 2021

Commented:

Rik
on 2 Nov 2021

Community Treasure Hunt

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

Start Hunting!