Matlab通过计算生成矩阵

时间:2017-03-20 08:00:22

标签: matlab matrix output

所以我有这个代码,         CLC         数据= [1; 3; 4; 3; 5; 2; 5]         CNT =大小(数据,1)

data =

     1
     3
     4
     3
     5
     2
     5


cnt =

     7


im =

     2


im =

     1


im =

    -1


im =

     2


im =

    -3


im =

     3

我需要来自该代码的矩阵输出

但我的输出仍然像这样

im =

     2
     1
    -1
     2
    -3
     3

如何制作这种输出?

SELECT pr.NAME,
       pr.date_phy,
       pr.code,
       pd.totalAmount+pr.advance as TotalPaid,
pa.totalatten as TotalPresent
FROM   physiofit_registration pr
       LEFT JOIN (SELECT code,Sum(amount) totalAmount
                  FROM   physiofit_deposit
           group by code
                  ) pd
              ON (pr.code = pd.code)
          LEFT JOIN (SELECT code,Count(*) totalatten
                  FROM   physiofit_attendence
                  GROUP  BY code) pa
           ON pr.code = pa.code; 

我还是很困惑,得到了那样的输出?

1 个答案:

答案 0 :(得分:1)

如果你想保留for循环,你可以这样做:

cnt=size(data,1);
im = zeros(cnt-1,1); % create empty diff array
for i=2:cnt
    im(i-1)=(data(i)-(data(i-1))) % fill it 
end