Returning NaN after value=double(subs(function)) when set(handles.a, 'String', num2str(value)
1 view (last 30 days)
Show older comments
I am using Guide to build a project. I get the number to evaluate at:
Alt1=str2double(get(handles.Alt01,'String'));
I pull data from a table and create variables:
data=readtable("Stratos Jump Data.xlsx");
altt=table2array(data(:,1));
v=table2array(data(:,2));
h=table2array(data(1:21,3));
t=table2array(data(1:21,4));
g=table2array(data(1:21,5));
p=table2array(data(1:21,6));
ro=table2array(data(1:21,7));
mu=table2array(data(1:21,8));
I perform a least squares:
FVC=ls(altt,v);
Ft=ls(h,t);
Fg=ls(h,g);
Fp=ls(h,p);
Fro=ls(h,ro);
Fmu=ls(h,mu);
then evaluate the creasted functions at the Alt1:
X=Alt1
vc=eval(FVC)
t0=eval(Ft);
g1=eval(Fg);
p1=eval(Fp);
ro1=eval(Fro);
mu1=eval(Fmu);
I then try to set the handles so it populates my project:
set(handles.Velocity1,'String',num2str(vc,5));
set(handles.Ro1,'String',num2str(ro1));
set(handles.Temp1,'String',num2str(eval(Ft),5));
set(handles.gravity,'String',num2str(g1,5));
set(handles.pr1,'String',num2str(p1,5));
set(handles.viscosity,'String',num2str(mu1,5));
set(handles.drag,'String',num2str(FD,5));
but all handles return "NaN"
I verified the code is working in a seperate matlab file. but when trying to have it populate in guide it fails.
1 Comment
Walter Roberson
on 20 Dec 2023
FVC=ls(altt,v);
ls() requests a directory listing, not a least squared -- unless you have (unwisely) overridden ls
vc=eval(FVC)
eval() does not return any output -- unless you have (unwisely) overridden eval()
Answers (1)
arushi
on 20 Dec 2023
Hi Steven,
I understand that you are getting NaN values while setting the handles. Given the information provided, there are several potential issues that may be causing your GUIDE GUI to display "NaN" for all the values.
Check Alt1: Make sure that Alt1 is a valid numeric value and not NaN. If str2double fails to convert the string to a number (perhaps due to invalid input or formatting issues), it will return NaN.
Least Squares (ls) Function: MATLAB does not have a built-in function named ls for performing least squares fitting. You would typically use polyfit for polynomial fitting or the fit function from the Curve Fitting Toolbox. Ensure that the ls function you are using is correctly implemented and that it returns a function handle or coefficients that can be evaluated.
Try replacing eval : If FVC, Ft, etc., are function handles or coefficients, you should try use them directly to evaluate the fitted functions at Alt1.
If you are setting the handles within a GUIDE callback, ensure that there are no errors or exceptions occurring before or during the handle setting process. Check the MATLAB command window for any error messages.If you've verified that each individual part of your code works in isolation (as you mentioned it works in a separate MATLAB file) then the issue likely lies in the interaction between these parts within the GUIDE framework or with the state of the GUI at runtime.Feel free to provide the data file if the issue persists after following the above listed recommendations.
Hope this helps.
Thank you
0 Comments
See Also
Categories
Find more on Get Started with MATLAB 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!