MATLAB Answers

function call returns "index (1.2): subscripts must be either integers 1 to (2^63)-1"

조회 수: 25(최근 30일)
I have the following function:
u_1 = @(y) 2(1+y)/(4 + (1+y)^2);
I call it:
u_1(0.2)
I get the following error:
index (1.2): subscripts must be either integers 1 to (2^63)-1 or logicals
error: called from
@<anonymous> at line 1 column 20
Any help would be greatly appriciated. Thank you.

  댓글 수: 0

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

채택된 답변

danielle sisserman
danielle sisserman 26 Dec 2020
changed
2(1+y)/(4 + (1+y)^2);
to
2*(1+y)/(4 + (1+y)^2);
and it works.

  댓글 수: 0

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

추가 답변(1개)

James Tursa
James Tursa 26 Dec 2020
편집: James Tursa 26 Dec 2020
You are missing a multiply operator. There is no implied multiplication in MATLAB with the 2( combination. E.g.,
u_1 = @(y) 2*(1+y)./(4 + (1+y).^2);
I have also changed your operations slightly to make the function vectorized.

  댓글 수: 0

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by