So I am currently working with different datasets. Some are monthly, some daily, but I want quarterly. This is why I wrote the following function:
function y = average2(data, frequency)
% Monthly/Daily data to quarterly data by taking average
% INPUT data Nx2 monthly/daily data
% OUTPUT y Mx2 quarterly data
% USAGE average2(data)
if frequency == 'monthly';
K = 1:3:(length(data)-3);
quarterly = (data(K, 2)+data(K+1, 2)+data(K+2, 2))/3;
timevector = data(K, 1);
y = [timevector quarterly];
elseif frequency == 'daily';
y = data*data; %just as an example, not correct calculation
else frequency ~= 'daily' || 'monthly';
error('Requested frequency not available');
end
(the calculation of daily is not the problem). So my Problem is the following: If I use the monthly option, everything works fine. But everytime I use something different than 'monthly' as frequency in my function, I get the error message:
Matrix dimensions must agree.
Error in average2 (line 8)
if frequency == 'monthly';
Therefore activating the elseif clause and processing the input I get in frequency doesn't work. Does anyone know where I have a mistake? Thanks in advance