MATLAB: User defined variable input

user

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

Best Answer

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'.
Related Question