How to call element from vector out of t = @(theta) x*cos(theta)-y*sin(theta);
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ole
el 13 de Mzo. de 2015
Editada: Star Strider
el 13 de Mzo. de 2015
x = linspace(1,10,10);
y=x;
t = @(theta) x*cos(theta)-y*sin(theta);
t(0.1) will give me vector. How to get element 5 ?
0 comentarios
Respuesta aceptada
Star Strider
el 13 de Mzo. de 2015
My approach:
tv = t(0.1);
t5 = tv(5) % Element 5
2 comentarios
Star Strider
el 13 de Mzo. de 2015
Editada: Star Strider
el 13 de Mzo. de 2015
My pleasure.
Unfortunately, not.
The only way around it is to include ‘x’ and ‘y’ as arguments, then reference the 5th element of each:
txy = @(theta,x,y) x*cos(theta)-y*sin(theta);
t5 = txy(0.1,x(5),y(5))
----------
This strange construction actually works (it creates a cell array, and then references the 5th element and assigns the correct value to t5), but throws an annoying error and halts execution of the script:
t5 = {t(0.1)}(5)
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!