Effacer les filtres
Effacer les filtres

Dummies on dates MATLAB

3 vues (au cours des 30 derniers jours)
Ali Akbar
Ali Akbar le 10 Avr 2015
Commenté : Ali Akbar le 11 Avr 2015
I have a calendar with specific dates that I want to create dummy variables for.
The calendar is from 1991 to 2014 and there are announcements on different days of the month throughout the time period. This is how it looks:
First column years, second months and third days.
I have the announcement dates that I want to fit to this calendar with dummy variables. These dates look like this:
How do I create an array with the length of my first calendar with 1 for the days of announcement (second calendar) and 0 otherwise. I need to somehow distinguish the different months from each other while assigning 1 to the dates.

Réponse acceptée

Brendan Hamm
Brendan Hamm le 10 Avr 2015
We can do this with the ismember(A,B) function, which returns a logical vector the length of A indicating whether the corresponding element in A appears in B. We can pass in an optional input argument to make this act on the rows of A and B, which we will need to do here on the first 3 columns of each of your variables..
calIdx = ismember(calendar(:,1:3),CPI_cal(:,1:3),'rows');
  1 commentaire
Ali Akbar
Ali Akbar le 11 Avr 2015
On the spot. Thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by