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

28 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Image Analyst
Image Analyst il 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 Commenti
Image Analyst
Image Analyst il 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);

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by