필터 지우기
필터 지우기

User defined function error

조회 수: 1 (최근 30일)
saravanakumar D
saravanakumar D 2014년 1월 24일
편집: Walter Roberson 2014년 1월 24일
This is my user defined fumction
function color_val= color(y,x)
for j=1:3
red(j)=RGB(y,x,j);
end
color_val=red;
But i get this error:-
Error: File: connect.m Line: 153 Column: 1
Function definitions are not permitted in this context.

채택된 답변

G PRAKASH
G PRAKASH 2014년 1월 24일
편집: Walter Roberson 2014년 1월 24일
program and function definition must be in separate files and function file must have same name as function
% main file
y = 1;
z = 2;
b = myfunc(y ,z)
disp(b)
% separate file with same fun name
function a = myfunc(y ,z)
a=x+z;
or
function main
y = 1;
z = 2;
b = myfunc(y ,z)
disp(b)
function a = myfunc(y ,z)
a=x+z;

추가 답변 (1개)

ES
ES 2014년 1월 24일
Did you run the code in command window?
Matlab functions should be in m files, and as said above, the name of the function should be callable (i.e., the name of the file name should be same as the function.
Eg:
FileName is my_function.m
content of the file:
function ret_val=my_function(input1,input2)
ret_val=input1+input2;
then from command line you can call your my_function.
>> my_function(5,3)
8

카테고리

Help CenterFile Exchange에서 Biotech and Pharmaceutical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by