MATLAB - 将for循环中的值分配给数组

时间:2018-03-29 23:48:01

标签: arrays matlab loops

SELECT t.zip_code AS area
     , MAX(IF(t.i=0,man_days_remaining,0)) AS d0_mdr  -- day 0 man days remaining
     , MAX(IF(t.i=1,man_days_remaining,0)) AS d1_mdr  -- day 1 man days remaining
     , MAX(IF(t.i=2,man_days_remaining,0)) AS d2_mdr  -- day 2 man days remaining
     , MAX(IF(t.i=3,man_days_remaining,0)) AS d3_mdr  -- day 3 man days remaining
 FROM (
        SELECT doa.zip_code
             , n.i
             , COUNT(DISTINCT w.user_ptr_id) AS man_days_remaining
          FROM ( SELECT DATE([daterange_start]) + INTERVAL 0 DAY AS dt ) i
         CROSS
          JOIN ( SELECT 0 AS i
                 UNION ALL SELECT 1
                 UNION ALL SELECT 2
                 UNION ALL SELECT 3
                 UNION ALL SELECT NULL
               ) n
          JOIN geography_operatingarea doa
            ON doa.active = 1
          LEFT
          JOIN domestic_worker_worker_operating_areas dwoa
            ON dwoa.operatingarea_id = doa.id
          LEFT
          JOIN domestic_worker w
            ON w.user_ptr_id = dwoa.worker_id
          LEFT
          JOIN domestic_worker_days_available d
            ON d.worker_id = w.user_ptr_id
           AND d.weekday_id = WEEKDAY(i.dt + INTERVAL n.i DAY) + 1

            -- exclude matches using NOT EXISTS with correlated subquery
         WHERE NOT EXISTS 
               ( SELECT 1
                   FROM domestic_jobcard dj
                   JOIN booking_booking bb
                     ON bb.id = dj.booking_id
                    AND bb.booking_status = 'confirmed'
                    AND DATE(bb.appointment_datetime) = i.dt + INTERVAL n.i DAY
                  WHERE dj.worker_id = d.worker_id
               )

         GROUP
            BY doa.zip_code
             , n.i
        ) t
  GROUP BY t.zip_code

我有25个文件,这段代码正在循环,我需要存储每个' ETotal'值为25x1矩阵。我该怎么办?

1 个答案:

答案 0 :(得分:1)

如果我理解你的问题,那么这是一个建议。你不能做类似以下的事情:

Etotal = zeros(number_of_files, 1);    % This should go before the beginning of for-loop

Etotal(index, 1) =  max(y);    % Replace "Etotal = max(y)" with this line