What is the function of [~,n]=size(p) in MATLAB?

You can post your problem related to MATLAB Projects here. We will try our best to help you out.
Armistead
Posts:12
Joined:Sat Feb 18, 2017 5:57 am
What is the function of [~,n]=size(p) in MATLAB?

Post by Armistead » Mon Mar 06, 2017 12:09 pm

I've searched on the internet, but I can't figure out what this expression is useful for.

Code: Select all

function [val]=f_obiectiv(p) % functia obiectiv din problema celor n regine
%{ 
gradul de "neconformitate" a unei permutari: numarul de pozitii distincte de pe tabla 
de sah pentru care reginele plasate in acele pozitii sunt in situatie de atac 
%}

[~,n]=size(p);  

val=0;

for i=1:n
    for j=i+1:n
        if(abs(i-j)==abs(p(i)-p(j)))
            val=val+1;
        end;
    end;
end;

% calitatea permutarii: numarul total de perechi de pozitii (regine) posibile - 
% numarul de perechi "neconforme" 

val=n*(n-1)/2-val;

end

Post Reply