why do i get NaN?
1 次查看(过去 30 天)
显示 更早的评论
b, z numbers come out but from there onwards e, w, j, k, t and the others leave NaN why?
b=(str2double(get(handles.edit12,'string'))-str2double(get(handles.edit10,'string')))/(str2double(get(handles.edit11,'string'))-str2double(get(handles.edit8,'string')))
z=(str2double(get(handles.edit14,'string'))-str2double(get(handles.edit12,'string')))/(str2double(get(handles.edit13,'string'))-str2double(get(handles.edit11,'string')))
e=(str2double(get(handles.edit16,'string'))-str2double(get(handles.edit14,'string')))/(str2double(get(handles.edit15,'string'))-str2double(get(handles.edit13,'string')))
w=(str2double(get(handles.edit18,'string'))-str2double(get(handles.edit16,'string')))/(str2double(get(handles.edit17,'string'))-str2double(get(handles.edit15,'string')))
j=(str2double(get(handles.edit20,'string'))-str2double(get(handles.edit18,'string')))/(str2double(get(handles.edit19,'string'))-str2double(get(handles.edit17,'string')))
k=(z-b)/(str2double(get(handles.edit13,'string'))-str2double(get(handles.edit18,'string')))
t=(e-z)/(str2double(get(handles.edit15,'string'))-str2double(get(handles.edit11,'string')))
l=(w-e)/(str2double(get(handles.edit17,'string'))-str2double(get(handles.edit13,'string')))
n=(j-w)/(str2double(get(handles.edit19,'string'))-str2double(get(handles.edit15,'string')))
b0=str2double(get(handles.edit10,'string'))
y=b0+b*(x-str2double(get(handles.edit8,'string')))+k*(x-str2double(get(handles.edit8,'string')))*(x-str2double(get(handles.edit11,'string')))
回答(1 个)
Walter Roberson
2017-11-5
I recommend doing each str2double only once and assign each to a meaningful variable name and then do the calculations. You can examine the variables to see if you got any nan, which is possible if the corresponding string did not represent a scalar double. You can also get nan from 0/0
4 个评论
Walter Roberson
2017-11-5
What you posted does not tell us what is stored in the strings. Show us the result of get() of each of the handles used in the formula
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!