I am very new to MATLAB, as in, started two days ago because I'm trying to translate some code from mathematica.
For context x0 = 1 and x,x2 are undefined in this function
function [f355] = f355(x,x0,x2)
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
if x >= 0
f355 = (Omega00)*sqrt((1)+((Lambda355*x)/(pi*(Omega00))^2));
elseif (x<=(x2+x1+x0))&&(x>=x0)
f355 = NewBWaist(Omega00,x0,f,Lambda355)*sqrt((1)+(Lambda355*(x-x0-x1)/(pi(Omega01)^2)));
else x >= (x0+x1+x2)
f355 = NewBWaist(NewBWaist(Omega00,x0,f1U,Lambda355),x2,f2U,Lambda355)*sqrt((Lambda355(x-sumxU))/(pi*(Omega02)^2));
end
When I run "f355(10,1,20)" I get an error
"Index in position 1 exceeds array bounds. Index must not exceed 1.
Error in m118codeInprogress (line 111)
f355(10,1,20)"
Any advice would be most welcome. Thanks.

댓글 수: 3

Dyuman Joshi
Dyuman Joshi 2023년 2월 24일
편집: Dyuman Joshi 2023년 2월 24일
There are un-defined variables in your code - Omega00, Lambda355, etc. Please specify their values.
Also, do not use the same name for function and a variable, as it overwrites the assignment.
Theobold
Theobold 2023년 2월 24일
Apologies,
Omega00= 3.5
Lambda355= 0.000355
The rest of the variables are themselves defined by other functions with yet more variables. The other functions are all working though.
Dyuman Joshi
Dyuman Joshi 2023년 2월 24일
Rename your output variable name and run your code. As other functions are working properly, your code should work after the correction as well.

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

 채택된 답변

Jan
Jan 2023년 2월 24일
이동: Jan 2023년 2월 24일

1 개 추천

Avoid using the name of the function as name of the output. This is confusing only.
Which is the failing line? In this line f355 is used as a variable, not as a function.
See this example:
sin(0.1) % Fine
sin = 15; % Now sin is a variable
sin(0.1) % Error: 0.1 is no valid index

댓글 수: 1

Theobold
Theobold 2023년 2월 24일
Right I see, I ran a calculation earlier (since deleted) with f355= so I guess it's now assigned as a variable?
Thanks for the advice.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 2월 24일

댓글:

2023년 2월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by