Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
Optimization Help

Subject: Optimization Help

From: Gregory Carnegie

Date: 2 Dec, 2010 12:01:05

Message: 1 of 1

I have an NxN matrix, and the following code finds the distan for each column of omega with all of the columns of omega.

Does anybody know, a better way of doing this?

Thanks in advance for your time.

threshold = zeros(N);
    for i = 1:N
        if disf == 1
            % euclidian distance weight function of each image
            threshold(:,i) = sum(bsxfun(@minus, omega,omega(:,i)).^2).^0.5;
        elseif disf == 2
            % manhattan distance weight function of each image
            threshold(:,i) = sum(abs(bsxfun(@minus, omega,omega(:,i))));
    threshold = max(mean(threshold)) + 0.0001; % Calculates the threshold weight distance

I am interested in vectorizing this, but i'm new to the 'bsxfun' function.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us