MathLab 2019 backward compatibility

The following code compiles and runs fine in '9.7.0.1216025 (R2019b) Update 1'
function approx = test3(x,N)
approx = zeros(N,1);
approx(1) = x + 1;
for i = 2:N
approx(i) = approx(i - 1) + x^i / factorial(i);
end
end
However, when I try and run it in my 2017 Uni environment, I get the following error:
Output argument "output" (and maybe others) not assigned
during call to "factorial".
Error in test3 (line 5)
approx(i) = approx(i - 1) + (x^i) / factorial(i);
Any ideas please?

답변 (1개)

J. Alex Lee
J. Alex Lee 2019년 12월 4일

0 개 추천

is it possible that in your 2017 environment, you have inadvertently overloaded the "factorial" function?

댓글 수: 5

andrew boar
andrew boar 2019년 12월 4일
Thank you for the prompt response.
I doubt that is the answer though as we are running the routine with parameter N set to 5.
Typical test data is:
test3(1.5, 5)
!5 = 120 so that doesnt sound like an overload situation?
Overloading as in there are multiple files named factorial.m
What is the output of
which -all factorial
Rename any that aren't base in matlabroot.
andrew boar
andrew boar 2019년 12월 4일
I have to say, I do have a number of years experience with many high level languages, but i am very new to MathLab. Are you saying that MathLab has access to four versions of factorial.m and does not know which one to use?
This output is from the 2017 environment.
>> which -all factorial
C:\Users\ttssb2\OneDrive - My University\MATLAB\factorial.m
C:\Program Files\MATLAB\R2017a\toolbox\distcomp\parallel\@codistributed\factorial.m % codistributed method
C:\Program Files\MATLAB\R2017a\toolbox\distcomp\gpu\@gpuArray\factorial.m % gpuArray method
C:\Program Files\MATLAB\R2017a\toolbox\symbolic\symbolic\@sym\factorial.m % sym method
C:\Program Files\MATLAB\R2017a\toolbox\matlab\specfun\factorial.m
Sean de Wolski
Sean de Wolski 2019년 12월 4일
Yes. This is the default one that ships with MATLAB that you're probably intending to call but aren't:
C:\Program Files\MATLAB\R2017a\toolbox\matlab\specfun\factorial.m
The other three in matlabroot are overloaded ones for those specific data types. The one in OneDrive is shadowing the specfun one that you're intending to call. Rename the OneDrive one to myFactorial or something to avoid the conflict.
andrew boar
andrew boar 2019년 12월 5일
Many thanks.
I can confirm this had completely resolved the issue.
Brilliant!

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2019년 12월 4일

댓글:

2019년 12월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by