counting across complementary columns

조회 수: 1 (최근 30일)
Wesso
Wesso 2019년 3월 17일
편집: Guillaume 2019년 3월 18일
I wrote a long function (attached so that you know it is not a post by a lazy student seeking an answer for his assignment) nd then I sensed that what I wrote is long and rediculous and coule be full of mistakes (still incomplete). I hope you can help
In short I have column A(daily date numbersover 4 years) and 5 columns that i want to count. Column B is always 1 and it is equals to the sum of rows in columns C,D,E, and F. So, Column C, D, E,F are complementary: if row C=1,rows D,E,and F must be zeros;if row D=1,rows C,E,and F must be zeros;if row E=1,rows C,D,and F must be zeros;and finally if row F=1,rows C,D,and E must be zeros;
How can do the counting in two ways
  1. count the number of observations in columns B,C,D,E, and F for every day of every month of every year
  2. count the number of observations in columns B,C,D,E, and F for every month of every year
I feel that it is much easier to compute than reporting a long fucntion with loops. I appreciate any assistance.
  댓글 수: 2
Rik
Rik 2019년 3월 17일
Since you have only ones and zeros in the B-F columns, you can use them as logical indices to the A column and the do the analyses you need on a vector with only observation dates.
You might also need a function like accumarray, but I don't understand what you mean well enough to give a definitive answer on that account.
Guillaume
Guillaume 2019년 3월 17일
편집: Guillaume 2019년 3월 18일
Please give an example of input and desired output, preferably using valid matlab syntax as comments to the question.
If you post your comments as answers, it looks like 2 people have already answered your question, so answerers may not even look at the question.

댓글을 달려면 로그인하십시오.

답변 (1개)

Wesso
Wesso 2019년 3월 18일
i will stick to b since it is more important to my analysis:
Capture.PNG
  댓글 수: 1
Wesso
Wesso 2019년 3월 18일
i don't know why column F doesn't appear in the image although in the original image it does. I am upliading an excel file as well

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by