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}
  1 件のコメント
Leon
Leon 2019 年 10 月 17 日
Exactly where the issue is. Many thanks!

サインインしてコメントする。

その他の回答 (0 件)

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by