reshape() error in the function created by matlabFunction()
이전 댓글 표시
matlabFunction() has generated for me AmplAndDers() to be used in fminunc(). The very first objective function evaluation fails:
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
Error in AmplAndDers (line 93)
Hess = reshape([-t2.*t3.*t4. ... .*(3.0./4.0)],[4,4]);
The signature of the function is:
function [Ampl,GradA,Hess] = AmplAndDers(C1_0,C2_0,R1_0,R2_0,w,x1,x2,x3,x4)
I call it with a w being an array. Two other outputs are returned correctly. I do not understand what does the above suggestion mean:
Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
If I manually change the above reshape() call to end with:
...*(3.0./4.0)],[4,4,length(w)]);
the program runs OK.
How can avoid the manual intervention?
댓글 수: 4
Valeri Aronov
2021년 8월 24일
편집: Valeri Aronov
2021년 8월 24일
Stephen23
2021년 8월 24일
"The very first objective function evaluation fails:"
Can you please show the exact code you use when supplying that function to FMINUNC.
Valeri Aronov
2021년 8월 24일
편집: Valeri Aronov
2021년 8월 24일
Valeri Aronov
2021년 8월 24일
채택된 답변
추가 답변 (1개)
KSSV
2021년 8월 21일
Read the documentation of reshape and understand it. The error is clear, you are trying to create extra elements than present in the array while reshaping.
Example:
A = rand(1,25) ;
B = reshae(A,5,5) ; % 5*5 = 25, no error as same elements present
C = reshape(A,6,5) ; % 6*5 = 30, error as A as 30 elements only.
댓글 수: 1
Valeri Aronov
2021년 8월 21일
편집: Valeri Aronov
2021년 8월 22일
카테고리
도움말 센터 및 File Exchange에서 Operations on Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!