Why is the length of these two variables are different?

조회 수: 1 (최근 30일)
Leon
Leon 2019년 10월 17일
댓글: Leon 2019년 10월 17일
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