How to pass variables from a matlab file to function in another file
조회 수: 13 (최근 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?
댓글 수: 1
Stephen23
2017년 2월 7일
You need to do these tutorials:
And then read these:
and then simply pass the values as input/output arguments.
채택된 답변
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
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 Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!