How to pass variables from a matlab file to function in another file
13 views (last 30 days)
Show older comments
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 Comment
Stephen23
on 7 Feb 2017
You need to do these tutorials:
And then read these:
and then simply pass the values as input/output arguments.
Accepted Answer
Image Analyst
on 7 Feb 2017
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 Comments
Image Analyst
on 10 Feb 2017
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);
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!