How to use a vector as an input in a function?
Afficher commentaires plus anciens
I have made this function:
function [AR,DEC] = astrometry(x,y,A,B,C,D,E,F)
AR = A*x+B*y+C;
DEC = D*x+E*y+F;
end
And I want to use some vectors as input:
input=[1,2,3,4,5,6,7,8]
But using:
[AR,DEC]=astrometry(input)
Gives me the following error:
Not enough input arguments.
Error in astrometry (line 2)
AR = A*x+B*y+C;
1 commentaire
Matt
le 21 Oct 2022
The function astrometry is expecting 8 inputs ( x,y ,a,b,... e,f) and you only give one input : a vector of size 1x8.
You can etheir write
[AR,DEC]=astrometry(input(1),input(2),input(3),...,input(8));
or define the function differently :
function [AR,DEC] = astrometry(input)
AR = input(1)*input(3)+ ...
DEC = ...
end
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 21 Oct 2022
inputcell = num2cell(input) ;
[AR,DEC] = astrometry(inputcell{:});
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!