M_Z
M_Z

Reputation: 201

How to extract one column from Matlab matrix?

I have the following code:

N = 10;
params = cell(N-3,4);
step = 1;
for i = 3 : N-1
    
    % Calibrate the camera
    [cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
        'EstimateSkew', false, 'EstimateTangentialDistortion', false, ...
        'NumRadialDistortionCoefficients', 2, 'WorldUnits', 'centimeters', ...
        'InitialIntrinsicMatrix', [], 'InitialRadialDistortion', [], ...
        'ImageSize', [mrows, ncols]);

    
   %disp(cameraParams.IntrinsicMatrix(1,1));
   %params = [params, cameraParams.IntrinsicMatrix(1,1)];
   params{step} = [cameraParams.IntrinsicMatrix(1,1),...
                      cameraParams.IntrinsicMatrix(2,2),...
                        cameraParams.PrincipalPoint(1),...
                        cameraParams.PrincipalPoint(2)];
                    
   disp(cell2mat(params(step)));
   %disp(cell2mat(cellfun(@(x)   params(:,1),'uniformoutput',false)));
   step = step +1;
   
end

and I need to extract each one of the columns (from 1, 4) from "params" matrix to plot their values... how can I do it?

when I try:

T = cell2table(params,...
'VariableNames', {'fx', 'fy', 'u0', 'v0'});
disp(T);

I get:

enter image description here

Upvotes: 0

Views: 224

Answers (1)

rinkert
rinkert

Reputation: 6863

There is no need to store your params in a cell array here. Instead, just initialize params as a array with NaN's or zeros.

Then set the appropriate row for a step in params:

N = 10;
params = NaN(N-3,4); % or zeros(N-3,4);
step = 1;
for k = 3 : N-1
    params(step,:) = rand(1,4);
    step = step + 1;
end

T = array2table(params,'VariableNames', {'fx', 'fy', 'u0', 'v0'})

Which will produce

>> T
T =
  7×4 table
       fx          fy         u0         v0   
    ________    ________    _______    _______
    0.015403    0.043024    0.16899    0.64912
     0.73172     0.64775    0.45092    0.54701
     0.29632     0.74469    0.18896    0.68678
     0.18351     0.36848    0.62562    0.78023
    0.081126     0.92939    0.77571    0.48679
     0.43586     0.44678    0.30635    0.50851
     0.51077     0.81763    0.79483    0.64432

Upvotes: 2

Related Questions