将输出保存到单元格

时间:2014-07-17 00:46:06

标签: matlab cell

我想将循环的输出保存到单元格中。现在,它全部保存为一个大单元格,但我希望在查看WAS_openWAS_close(即j计数器)中的每一行后输出保存为细胞阵列内的不同细胞。

O3_time = cell2mat(SARP2014_O3(:,2)); % Time data was taken
O3_data = cell2mat(SARP2014_O3(:,3)); % Data

% WAS
WAS_open = cell2mat(SARP2014_VertWAS(:,5)); % Open can time
WAS_close = cell2mat(SARP2014_VertWAS(:,6)); % Close can time
WAS_snake = cell2mat(SARP2014_VertWAS(:,1)); % Snake number

format long

k = 1;
for j = 1:length(WAS_open) % Number of observations for O3
    for i = 1:length(O3_time); % Number of cans
        if O3_time(i) >= WAS_open(j) && O3_time(i) <= WAS_close(j) % For all O3 between open and close times
            new_array{k}' = O3_data(i); % Save the O3 data that falls between the open and close times
            k = k+1;
        end
    end
end

基本上,在SARP2014_VertWAS的每一行中,都有一个开放时间和一个关闭时间。我想找到介于这两次之间的O3数据(每秒测量一次)并将其保存到单元格中。因此,第1行中打开和关闭时间之间的数据将保存在new_array {1}中,第2行中打开和关闭时间之间的数据将保存在new_array {2}等中。

然后,我需要找到每个细胞的平均值并将其附加到SARP2014_VertWAS。

SARP2014_VertWAS的片段:

Snake   Can      Flight Date    Open time           Close time
1901    7136    'RF219' 735774  735600.685763889    735600.686030093
1916    6057    'RF219' 735774  735600.686458333    735600.686932870
1917    8300    'RF219' 735774  735600.687152778    735600.687592593
1902    7169    'RF219' 735774  735600.687847222    735600.688310185
1915    6129    'RF219' 735774  735600.688541667    735600.688993056
1918    8279    'RF219' 735774  735600.689432870    735600.689872685
1903    7127    'RF219' 735774  735600.690277778    735600.690729167
1914    6102    'RF219' 735774  735600.693402778    735600.693796296
1919    8203    'RF219' 735774  735600.693877315    735600.694259259
1904    7203    'RF219' 735774  735600.694328704    735600.694699074

SARP2014_O3阵列的片段:

735773  735600.690659722    0.521049000000000
735773  735600.690671296    0.521049000000000
735773  735600.690682870    0.521049000000000
735773  735600.690694445    1.42528000000000
735773  735600.690706019    1.42528000000000
735773  735600.690717593    1.42528000000000
735773  735600.690729167    1.42528000000000
735773  735600.690740741    2.39701000000000
735773  735600.690752315    2.39701000000000
735773  735600.690763889    2.39701000000000
735773  735600.690775463    NaN

1 个答案:

答案 0 :(得分:0)

拉出数据并跟踪每条蛇的开启和关闭时间之间的点数。然后,使用找到的内容(点数)找到平均值作为索引。

k = 1;
num_of_pts = zeros(120,1);
O3_WAS = zeros(5329,1);
for j = 1:length(WAS_open) % Number of observations for O3
    tick = 0;
    for i = 1:length(O3_time); % Number of cans
        if O3_time(i) >= WAS_open(j) && O3_time(i) <= WAS_close(j) % For all O3 between open and close times
            O3_WAS(k) = O3_data(i); % Save all O3 data from that WAS can to a new array
            array(j) = O3_data(i); % Save all O3 data from that WAS can to a new array
            tick = tick+1; 
            % avg_O3(j) = nanmean(new_array(k)); % Average all O3 data from that can
            k = k+1; % Advance the counter
        end
    end
    num_of_pts(j) = tick;
end

avg_O3 = zeros(120,1);
% Find the average O3 during the interval each can was open
for n = 1:length(WAS_open-1)
    for i = 1:sum(num_of_pts)
        if n == 1
            avg_O3(1) = nanmean(O3_WAS(1:num_of_pts(n))); % First one
        else
            avg_O3(n) = nanmean(O3_WAS(num_of_pts(n-1)+1:((num_of_pts(n-1)+num_of_pts(n)))));
        end
    end
end