user defined variable input

3 vues (au cours des 30 derniers jours)
Anik SARKER
Anik SARKER le 5 Mar 2018
Commenté : Anik SARKER le 5 Mar 2018
If i have sample formula k=aX1*aX2*aX3*......*aXn. here X1,X2,...Xn are vector of X=[X1 X2 ... Xn]... if user input has only 2 component X1,X2 the output will be k=aX1*aX2. if user has n component in the vector then the output will be k=aX1*aX2*aX3*......*aXn. how to solve such a case

Réponse acceptée

ES
ES le 5 Mar 2018
Get the user input of X using input function. Then get the length of X using length function.
Run a for loop on length of X and multiply with 'a'.
  2 commentaires
Stephen23
Stephen23 le 5 Mar 2018
Note that it is recommended to avoid length, and only use numel or size. This avoids bugs caused by length measuring different dimensions without warning.
Anik SARKER
Anik SARKER le 5 Mar 2018
thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by