Why my user-defined matlab function returns NaN?

조회 수: 3 (최근 30일)
Ramiro
Ramiro 2023년 12월 14일
이동: Voss 2023년 12월 14일
I wrote a matlab function but when the input argument vector has only one element, it returns NaN. I checked my code and I think everything is OK.
The W argument is a n x 1 vector or a 1 x n vector of weights that sum 1. However, when W = 1, the function returns NaN.
I think it is a bug of my Matlab version (2023b for Mac Intel).
Thanks in advance for your help.
Ramiro
W = 1;
orn = Orness(W)
orn = 1
function orn = Orness(W)
nW = numel(W);
if nW >= 2
orn = zeros(nW,1);
for j = 1:nW
orn(j) = ((nW-j)/(nW-1))*W(j);
end
orn = sum(orn);
elseif nW == 1
orn = 1;
end
end
  댓글 수: 1
Torsten
Torsten 2023년 12월 14일
I cannot reproduce the behaviour you describe (see above).

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

채택된 답변

Ramiro
Ramiro 2023년 12월 14일
이동: Voss 2023년 12월 14일
Hi, thank you for the command. My path have two Orness functions (one very old). The script is using that function instead of the new one.
So I made the mistake. I renamed the new function and the problem is fixed.
This solved my issue.
Regards
Ramiro

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by