"Undefined function or variable 'x'." for input of function

조회 수: 6 (최근 30일)
eren baris alici
eren baris alici 2018년 3월 31일
댓글: Birdman 2018년 4월 1일
im extremely new on matlab, tried to write a code like this. my issue is when i try to see the 'y' i see "Undefined function or variable 'x'." for input of function". here is the code of mine. i can see the x but when i press for y i cant see it.
function [z]= trial(x,y)
x=1:1:7
y=x+3;
z=x.*y;
end

답변 (1개)

Birdman
Birdman 2018년 3월 31일
편집: Birdman 2018년 3월 31일
Give x and y as input argument from outside as follows:
x=1:7;
y=x+3;
Then call the function from command line, do not press the green Run button the run the function:
z= trial(x,y)
Also, this tutorial should help:
  댓글 수: 2
eren baris alici
eren baris alici 2018년 3월 31일
did not work. i press enter after z= trial(x,y) and take same error. when press just trial i can see every variables value.
Birdman
Birdman 2018년 4월 1일
Have you saved your function like this?
function [z]= trial(x,y)
z=x.*y;
end
After doing this, call from command as follows:
x=1:7;
y=x+3;
z= trial(x,y)

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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by