Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do I set up a particular function

조회 수: 3 (최근 30일)
ektor
ektor 2019년 5월 15일
마감: MATLAB Answer Bot 2021년 8월 20일
Dear all,
I have a function
f=@(x) umax(x,u, t);
The problem is that x changes at each value of t=1,...,T; that is,
LL= function umax(x,u, t);
if t==1
u=[x; u(2:T) ];
elseif t==T
u=[u(1:T-1);x ];
else
u=[u(1:t-1);x;u(t+1:T) ];
end
LL='some function of the sum of u which I skip now'
end
Is the above code correct or the code below?
f=@(x) umax(x,u, t);
LL= function umax(x,u, t);
u(t)=x
LL='some function of the sum of u which I skip now'
end
LL produces a scalar.
Thanks a lot
  댓글 수: 5
Walter Roberson
Walter Roberson 2019년 5월 16일
The first one requires that a function named T has been defined that returns a scalar and that t is a nonnegative integer scalar. 0 is ok for t for the first one.
The second one is more efficient but requires that t be positive integer. 0 is not possible there. A vector or array of t is possible as long as x is scalar or the same number of entries.
ektor
ektor 2019년 5월 16일
Could you give me a particular code example as I am bit confused. Thanks.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by