Cant run a function

12 ビュー (過去 30 日間)
Anamil Mehta
Anamil Mehta 2020 年 9 月 16 日
コメント済み: KSSV 2020 年 9 月 16 日
Hi
I am only 3 days old in the MATLAb so please excuse my naiveness.
I am trying to write a very basic function to get a homogeneous matrix. however when i try to run it or to call the function in the cmd line i get the error saying 'error in practice1(line 3). Doesnt say what the problem is. I have defined the function in 'practice.m' and intend to call it using 'practice1.m' or directly in the cmd line.
What am i doing wrong here?

採用された回答

KSSV
KSSV 2020 年 9 月 16 日
You must define one function in a single file and save it in the name of the function.
function x = rot1(p)
% define your formula
end
Save the above in the name rot1.m. When you call it, just call by the name of function. Like below:
p = pi/4 ; % your value
x = rot1(p) ;
  2 件のコメント
Anamil Mehta
Anamil Mehta 2020 年 9 月 16 日
Thank you! that worked!
Does this mean that If i want to define 'n' functions, i have to create 'n' different files per function?
KSSV
KSSV 2020 年 9 月 16 日
If you want to have access from outside, yes you need to have n files for n functions. If you want to have access in a single main function, then you can define all the functions in a single main function.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by