Function requires more input arguments to run?
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I'm relatively new to matlab and trying to code a magnetic dipole field. Here is my code
if true
% code
function [Br,Btheta]=magfield(theta,rho,phi,Bo,Rs)
Bo=2000; %average magnetic field
Rs=2000; %radius of planet
Br=-2*Bo *(Rs/rho)^3 * cos(theta); %radial magnetic field dependence
Btheta=-Bo*(Rs/rho)^3 * sin(theta); %azimuthal magnetic field dependence
%[X,Y,Z]=sph2cart(theta, phi, rho);
end
However when I run this I get the error message "magfield requires more input arguments to run".
Does anyone have any idea why this might be occurring and how I can rectify it?
Thanks, John
1 commentaire
Réponse acceptée
Adam
le 25 Nov 2015
theta = 7;
rho = 10;
phi = 100;
Bo = 2;
Rs = 8;
[Br,Btheta] = magfield(theta,rho,phi,Bo,Rs);
is how you should call your function (as an example - obviously use your own sensible input values). If you do not then you will get that error because your function expects 5 inputs.
If you try to run it like you would a script, e.g. by just clicking 'Run' in the editor then it will try to call it with no arguments and will crash as soon as it tries to access the first of those input arguments it expected.
In your case Bo and Rs don't look like they should be input arguments because you immediately overwrite them in the function. Unless your intention is to remove the hard-coded overwrites and pass them in instead, but haven't got around to that yet.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Time Series Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!