Why am i getting this error message? "Array indices must be positive integers or logical values."

조회 수: 4(최근 30일)
x = 120;
for n=1:10
f= (x(cosh(600/x) -12)-108);
x_1 = x-(f/diff(f))
Array indices must be positive integers or logical values.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 10월 26일
In matlab (and most other programming-languages) you will have to write out the multiplication-operator (* for matrix multiplication or .* for elementwise multiplication). The way you write:
Will be interpreted as the cosh(600/x)-12th element of the matrix x. Note here that 600/x would be a right-matrix-division, for elementwise division you will have to use ./.
Most likely you want:
f= (x*(cosh(600/x) -12)-108);
Then you will have a problem with the next line too, because f is now a scalar which make the function diff return an empty array, [], so you will have to do something about that.
If you are very new to matlab take a trip through the on-ramp courses on the Matlab web-site.
  댓글 수: 5

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by