Why is the length of these two variables are different?

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2019-10-17
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}

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by