Array inside a function
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Adam
am 13 Jul. 2017
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
am 13 Jul. 2017
@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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!