How to write a function handle in vectorized form and avoid an error due to lengthy equation

2 views (last 30 days)
I want to write an objective function f(x) which is very much lengthy as shown below that appears the Error message '' output truncated text exceeds maximum line length''. There are questions:
(1) How can we put them into a function handle in vectorized form (applicable in ga);
(2) How to avoid the error due to lengthyy equation.
Please advise/help

Accepted Answer

James Tursa
James Tursa on 13 Dec 2020
Your post is inconsistent since it appears to need an even number of columns but you end your example with column 100001, an odd number. However, if you do have an even number of columns:
f = @(x) sum(x(:,1:2:end) .* x(:,2:2:end),2);

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!