Replacing symbolic vector with changing values

I have a symbolic vector with repeating entries, similar to:
(cos(x), cos(x), cos(x), cos(x+5), cos(x+5)...)
and what i want to do is replace x with incrementing values so I can plot it. I have tried subs but it does not work properly. If my vector is the one i defined, i want my result to be
(cos(1), cos(2), cos(3), cos(4+5), cos(5+5)...)
but evaluated so that I may graph it. Is there a simple way to do this? I wrote an EXTREMELY inefficient loop that accomplished this by substituting the variable for the entire vector then storing only the necessary element into an output array, but it cannot handle the size i need.
Thanks

 采纳的回答

syms x
y=[cos(x), cos(x), cos(x), cos(x+5), cos(x+5)]
out=arrayfun(@(x) eval(y(x)),1:numel(y))

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Labels and Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by