user defined variable input

조회 수: 2 (최근 30일)
Anik SARKER
Anik SARKER 2018년 3월 5일
댓글: Anik SARKER 2018년 3월 5일
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

채택된 답변

ES
ES 2018년 3월 5일
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
Stephen23
Stephen23 2018년 3월 5일
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 2018년 3월 5일
thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by