필터 지우기
필터 지우기

Array inside a function

조회 수: 1 (최근 30일)
carlos g
carlos g 2017년 7월 13일
댓글: Jan 2017년 7월 13일
I have the following function
U2=@(eta) i/alpha2*DV2(eta)-beta2/alpha2*W2VEC;
where W2VEC is a vector of N components and alpha2,beta2 are just numbers.
I would like to be able to evaluate U2 at N different eta, which correspond to the N components of W2VEC as well.
The way I am doing it leads to a NxN vector (every eta multiplies a N-component vector), but this is not what I want. I would like that each eta would correspond to a component of W2VEC.
Is it possible to do this having W2VEC declared already as an array of N given components? When I do U2(0), for example, I still get a vector. And what I want to obtain is a single value (corresponding to DV2(0), which is OK, and the first component of W2VEC, which fails). I know how to do this manually (using a loop and redefining U2 each time), but I would like to do it in a more sustainable way. Is that possible?
Conversely, even if W2VEC is a numeric array, is it possible to convert it to a kind of "function" so that I can access each component through the argument? (An therefore, being able to introduce this new "function" into U2)
  댓글 수: 2
Adam
Adam 2017년 7월 13일
You need to use component-wise operations .* and ./ rather than matrix based * and /
I'm not sure I fully understand why U2(0) still produces a vector output, but you haven't told us exactly what the sizes are of all the components and what DV2 is. Is it an array or a function?
Jan
Jan 2017년 7월 13일
@carlos g: It will be much easier to control the behavior of your function if you move it to a function, instead of the anonymous function in a one-liner.
W2VEC is a numeric array, is it possible to convert it to a kind
of "function" so that I can access each component through the
argument?
This sounds like you want to use an index of the array.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by