필터 지우기
필터 지우기

How to pass variables from a matlab file to function in another file

조회 수: 26 (최근 30일)
I have made a Matlab file SystemDetail.m where I have taken some data as input from the user. I have taken two matrices n, d and a constant o as input from the user in SystemDetail.m. I have another matlab function file GenAlgo.m. I want to use the value of n, d and o as an argument of a function in this function file GenAlgo.m. How should I do it? I have written function sysr = SystemDetail(n,d,o) in my file GenAlgo.m where n d and o are taken from user in SystemDetail.m I am getting the error ' Not enough input arguments. Please tell Where am I wrong?

채택된 답변

Image Analyst
Image Analyst 2017년 2월 7일
You could pass the values into the other function as input arguments, or you could pass in just the filename and let the other function read in the mat file itself. Or, if it's a constant, known filename, you wouldn't even have to pass in the filename, it will just know what it is because you hard coded it in.
  댓글 수: 6
Image Analyst
Image Analyst 2017년 2월 10일
You can't define SystemDetail in both m-files. It's defined in SystemDetail.s do do not define it again in GenAlgo.m. You need to CALL it in GenAlgo.m. So don't have the function keyword before systr. Also, as we can see from SystemDetail.m, SystemDetail() does not even return a value so you can't take the resul and put it into sysr. Finally, SystemDetail does not use the values of n, d, and order that you pass it - it immediately overwrites them with the results of input(). So either put the input lines in GenAlgo.m, or delete the input arguments.
Suggested fix:
SystemDetail.m
function SystemDetail(n,d,order)
g = tf(n,d)
bode(g)
figure
step(g)
% etc. -- other stuff with order or whatever...
GenAlgo.m
n = input('Enter the numerator coefficient from highest power to the lowest in square brackets')
d = input('Enter the denominator coefficient from highest power to the lowest in square brackets')
order = input('Enter the order of the system into which you wish your system be reduced to')
% Call SystemDetail()
SystemDetail(n,d,order);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by