필터 지우기
필터 지우기

Returning NaN after value=doub​le(subs(fu​nction)) when set(handles.a, 'String', num2str(value)

조회 수: 3 (최근 30일)
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
Walter Roberson
Walter Roberson 2023년 12월 20일
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()

댓글을 달려면 로그인하십시오.

답변 (1개)

arushi
arushi 2023년 12월 20일
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 str2doublefails 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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by