フィルターのクリア

how to access function from a different scipt?

4 ビュー (過去 30 日間)
tyler hollings
tyler hollings 2020 年 9 月 4 日
コメント済み: tyler hollings 2020 年 9 月 4 日
i keep getting an error that says "Local function name must be different from the script name." when i try to call a funtion from a different script
i know my funtion works i just dont know how to call if from a different script
clear all
close all
create_array(10,5,1)
function create_array(N,M,row_orient)
if row_orient==1
for i=1:N
for j=1:M
if N==M
x(i,j)= N*(i-1)+j
elseif M-N >=1 | N-M >= 1
x(i,j)=M*(i-1)+j
end
end
end
elseif row_orient==0
for i=1:N
for j=1:M
if N==M
x(j,i)= N*(i-1)+j
elseif M-N >=1 | N-M >= 1
x(j,i)=M*(i-1)+j
end
end
end
end
end

採用された回答

Steven Lord
Steven Lord 2020 年 9 月 4 日
That error message is correct. If you have a function inside a script file, the name of the function must not be the same as the name of the script. This is documented in the Note in the "Syntax for Function Definition" section on this documentation page.
As stated on this other documentation page functions in script files are not normally accessible outside that script file. If you want that function to be accessible one of the following must be true. [I don't think I missed any possibilities, but if I did these are the most common ways to make a function in a file accessible to the Command Window and other files.] The first is probably the easiest.
  • The function needs to be the main function in a function file (not a script file)
  • The script file needs to create a function handle to the function
  • The function file in which it is a local function needs to return a function handle to that local function, or
  • The function needs to be a method of a class
  2 件のコメント
tyler hollings
tyler hollings 2020 年 9 月 4 日
ok dumb question what is a funiton file and how do i make it? ive only ever used script files and creating a funtion file seems like the easiest thing to do
tyler hollings
tyler hollings 2020 年 9 月 4 日
never mind i figured out how to make the funtion file thank you steven lord!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by