필터 지우기
필터 지우기

How to create user defined function in matlab?

조회 수: 3 (최근 30일)
saravanakumar D
saravanakumar D 2014년 1월 22일
댓글: Image Analyst 2014년 1월 23일
I have use below set of code frequently. So i have to make user defined function
below is my frequently used code:-
x=xvalue;
y=yvalue;
for j=1:3;
red(j)=RGB(y,x,j);
end
shape.color=red;
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 22일
Can you explain what are the argument (inputs and outputs) of your function?
saravanakumar D
saravanakumar D 2014년 1월 22일
편집: saravanakumar D 2014년 1월 22일
input is x and y values
output is pixel color value -->shape.color= [242 0 12]

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

채택된 답변

Image Analyst
Image Analyst 2014년 1월 22일
편집: Image Analyst 2014년 1월 22일
I think this is the minimum necessary:
function shape = myFunction(RGB, xvalue, yvalue, i)
x=xvalue;
y=yvalue;
for j=1:3;
red(j)=RGB(y,x,j);
end
shape(i).color=red;
Optionally, x, y, and red could also be outputs, and shape could also be an input. Be aware that the "red" variable actually contains the red, green, and blue values from the pixel at (y, x).
  댓글 수: 6
Walter Roberson
Walter Roberson 2014년 1월 23일
shape.color=red;
creates "shape" as a structure with a field "color" that it sets to the content of "red". Then your statement
shape=shape.color
overwrites "shape" with the contents of the field "color", into which you had written the content of "red". The net effect of your code is as the same as if you had changed those last two lines to
shape = red;
Image Analyst
Image Analyst 2014년 1월 23일
Do you want a structure or not? If there is only one field, then I see no reason at all to use a structure. Just use a simple variable.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2014년 1월 22일
function shape = myFunction(RGB, xvalue, yvalue, i)
shape(i).color = squeeze(RGB(xvalue, yvalue, :));
  댓글 수: 2
saravanakumar D
saravanakumar D 2014년 1월 22일
which is output variable shape or shape(i).color?
Walter Roberson
Walter Roberson 2014년 1월 22일
The output variable is "shape", as listed in the function header. The "shape" that is output will be a structure array with a single field "color", with the "i"th element of the structure array populated with meaningful data and the rest of the shape(K).color will be the empty array []

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

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by