r_createFloeCircle.m 3.58 KB
function [floe] = r_createFloeCircle(nFrames,nObjects,xpos,ypos,camNumber)
% R_CREATE_FLOE - Creates the variable ''floe'' that contains the
%                 x-position of the floe and its y-position
%
% Syntax: 
%    [floe] = r_createFloeCircle(nFrames,nObjects,xpos,ypos,camNumber)
%
% Inputs:
%    nFrame    - The number of frame
%    nObjects  - The number of object
%    xpos      - The x-position 
%    ypos      - The y-position
%    camNumber - The camera number
%
% Example:
%    [floe] = r_createFloeCircle(250,5,2,450,4)
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: r_data_pos 
%
% Author: Marie-Pier Marquis, Dany Dumont
% UQAR/ISMER
% email: dany_dumont@uqar.ca
% Website: http://www.ismer.ca/dumont-dany
% October 2014
% ________________________________________________________________________
%%
% Sort data by position along the y-axis
floe = nan.*ones(nObjects,nFrames,2);
for n = 1:nFrames
    [sy,u] = sort(ypos(n,:),'ascend'); % r_recon returns y-position 
    if nObjects == 5
        for k = 1:nObjects
            if k == 1
                u1 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u1);
                    floe(k,n,2) = ypos(n,u1);
                end
            elseif k == 2
                u2 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u2);
                    floe(k,n,2) = ypos(n,u2);
                end
            elseif k == 3
                u3 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u3);
                    floe(k,n,2) = ypos(n,u3);
                end
            elseif k == 4
                u4 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u4);
                    floe(k,n,2) = ypos(n,u4);
                end
            elseif k == 5
                u5 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u5);
                    floe(k,n,2) = ypos(n,u5);
                end
            end
        end
        
    elseif nObjects == 3
        for k = 1:nObjects
            if k == 1
                u1 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u1);
                    floe(k,n,2) = ypos(n,u1);
                end
            elseif k == 2
                u2 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u2);
                    floe(k,n,2) = ypos(n,u2);
                end
            elseif k == 3
                u3 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u3);
                    floe(k,n,2) = ypos(n,u3);
                end
            end
        end
    elseif nObjects == 2
        for k = 1:nObjects
            if k == 1
                u1 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u1);
                    floe(k,n,2) = ypos(n,u1);
                end
            elseif k == 2
                u2 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u2);
                    floe(k,n,2) = ypos(n,u2);
                end
            end
        end
    else
        disp(' Error');
        return
    end
end

% Some unit conversion
% From pixel length to meters
if camNumber == 1
    floe(:,:,1) =  0.01.*floe(:,:,1) - 0.1;
elseif camNumber == 2
    floe(:,:,1) =  0.01.*floe(:,:,1) + 3.9;
elseif camNumber == 3
    floe(:,:,1) =  0.01.*floe(:,:,1) + 7.9;
elseif camNumber == 4
    floe(:,:,1) =  0.01.*floe(:,:,1) + 11.9;
end
floe(:,:,2) = -0.01.*floe(:,:,2) + 1.0;




end