Why is the length of these two variables are different?

1 visualización (últimos 30 días)
Leon
Leon el 17 de Oct. de 2019
Comentada: Leon el 17 de Oct. de 2019
I use the same number c to set the length of these two variables A (numerical) and B (string).
Why are their lengths are different at Station 3? Weird enough, if I only run Station 3, their length will be the same.
Here is my code and attached is the data.
clear all
close all
clc
%% --- load the file ---
load('test.mat'); % Sta
% Initialize each column:
ACCESSION = [];
CTDTEMP_ITS90_DEG_C = [];
for i=1:3 %length(Sta)
c = length(Sta{i}.depth); % number of depths
disp(['Number of depth levels:', num2str(c)]);
% Accession:
if isfield(Sta{i}, 'accession') == 1
[ACCN{1:c}] = deal(Sta{i}.accession);
else
[ACCN{1:c}] = deal('N/A');
end
B = ACCN';
ACCESSION = [ACCESSION; B];
disp(['length Accession:', num2str(length(B))])
%CTDTMP:
A = [];
if isfield(Sta{i}, 'ctdtmp') == 1
A = Sta{i}.ctdtmp;
else
A = -999*ones(c,1)
end
CTDTEMP_ITS90_DEG_C = [CTDTEMP_ITS90_DEG_C; A];
disp(['length of CTDTMP:', num2str(length(A))])
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Oct. de 2019
You do not truncate ACCN down to length c. ACCN had been 11 long because of the previous iterations; now only 10 are needed but you set ACCN{1:10} which does not remove the unneeded ACCN{11}

Más respuestas (0)

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by