Hello, I have a 2D array of data that is imported from Excel. The data is in the following format:
Data=[Date Shift Unit Code UpOn UpOff Down]
I have already sorted the data so that it is in date sequential order. But I have 0,1 or 2 entries for each date (using matlab's serial date format), Shift can be either a 1 or a 2. I need to sum the UpOff column for each date.
I would like to use a non-looping sort to generate this sum, something along the lines of:
DataSum = Data(Data(:,3)==1 & Data(:,2)==2,6) + Data(Data(:,3)==1 & Data(:,2)==1,6)
But the data may or may not have multiple entries so this format doesn't always generate matrices with the same number of rows for each side the summation. Is there another way that I can do this without resorting to using a loop and a test for each?

 採用された回答

dpb
dpb 2015 年 11 月 20 日

0 投票

[u,~,ib]=unique(Data(:,1)); % get the unique values and locations for each
sx(:,i)=accumarray(ib,Data(:,6)); % sum over the subsets

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2015 年 11 月 20 日

回答済み:

dpb
2015 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by