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
0 个评论
采纳的回答
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!