How to enter multiple values for a single input in a function
조회 수: 34 (최근 30일)
이전 댓글 표시
So what I'm trying to do is have a function take in a vector of inputs, and then use them seperately in a function. So the function would be something simple, like adding 1 to every input value, but I want the limit of input values to be practically infinite. So I want to assign the variable x to every component of a vector and add 1 to each component, then at the end I want to obtain the sum of every component in the vector. I don't quite know how else to ask this question, something like
x = [1, 2, 3 . . . .]
answer = sum(x+1)
댓글 수: 5
Nasir
2023년 9월 11일
can someone tell me about how to enter multiple values in single string
x = [1 2 3 4 5 6 ...............................................1000]
답변 (1개)
Asad (Mehrzad) Khoddam
2020년 9월 5일
Most Matlab functions are vector based. you should use .^ for vector based ^ and .* for vector based *
So you function line looks like this:
answer = sum((x+1).^2 .* mod(x, 2));
and ./ instead of /
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!