Hi All,
I am stuck at a point in writing some code.
Please look at this function Look at this function
-----------------------------------------------------------------------
[FONT="]%% Converting Cumulative "R" Values into Quarterly "Q" Values[/FONT]
[FONT="]% For the first quarter, "R" data and "Q" data are equivalent. For[/FONT]
[FONT="]% subsequent quaters (2, 3, & 4) the "Q" value is equivanet to the[/FONT]
[FONT="]% current quarter's value less the previous quater's value.[/FONT]
[FONT="] 1) [/FONT][FONT="]function[/FONT][FONT="] r = rToQ(obj)[/FONT]
[FONT="] 2) [/FONT][FONT="]if[/FONT][FONT="] obj.freq ~= [/FONT][FONT="]'R'[/FONT][FONT="], error([/FONT][FONT="]'obj frequency bust be "R"'[/FONT][FONT="]); [/FONT][FONT="]end[/FONT][FONT="];[/FONT]
[FONT="] 3) r = ifthen(obj.periods()==1, obj, obj - obj.lag(-1));[/FONT]
[FONT="] 4) r.freq = [/FONT][FONT="]'Q'[/FONT][FONT="];[/FONT]
[FONT="] 5) [/FONT][FONT="]end[/FONT]
-----------------------------------------------------------------------
As you can see the above function is used to change the cumulative data into quarterly data. I am trying to implement an ‘if else’ function
I am trying to create function called “ifthen” in Matlab (it is being called in line 4 in the code above) which checks for the period of the object. If it is 1 then the object remains unchanged. If is not 1 then the obj.lag is subtracted from the original obj.
How should I implement this “ifthen” function so that it returns an object? In other words how do I implement an element wise “ifthen “function on an object?
I tried to do something like this but this does not work on an object
[FONT="]function[/FONT][FONT="] r = ifthis( condition, result1, result2)[/FONT]
[FONT="] error(nargchk(3,3,nargin));[/FONT]
[FONT="]if condition == ([/FONT][FONT="]obj.periods()==1[/FONT])
[FONT="] r = obj;[/FONT]
[FONT="]else[/FONT]
[FONT="] r = obj-obj.lag(-1);[/FONT]
[FONT="]end[/FONT]
[FONT="]end[/FONT]
<o:p></o:p>
<o:p>Any help would be appreciated</o:p>
<o:p></o:p>
<o:p>-Thanks
</o:p>
I am stuck at a point in writing some code.
Please look at this function Look at this function
-----------------------------------------------------------------------
[FONT="]%% Converting Cumulative "R" Values into Quarterly "Q" Values[/FONT]
[FONT="]% For the first quarter, "R" data and "Q" data are equivalent. For[/FONT]
[FONT="]% subsequent quaters (2, 3, & 4) the "Q" value is equivanet to the[/FONT]
[FONT="]% current quarter's value less the previous quater's value.[/FONT]
[FONT="] 1) [/FONT][FONT="]function[/FONT][FONT="] r = rToQ(obj)[/FONT]
[FONT="] 2) [/FONT][FONT="]if[/FONT][FONT="] obj.freq ~= [/FONT][FONT="]'R'[/FONT][FONT="], error([/FONT][FONT="]'obj frequency bust be "R"'[/FONT][FONT="]); [/FONT][FONT="]end[/FONT][FONT="];[/FONT]
[FONT="] 3) r = ifthen(obj.periods()==1, obj, obj - obj.lag(-1));[/FONT]
[FONT="] 4) r.freq = [/FONT][FONT="]'Q'[/FONT][FONT="];[/FONT]
[FONT="] 5) [/FONT][FONT="]end[/FONT]
-----------------------------------------------------------------------
As you can see the above function is used to change the cumulative data into quarterly data. I am trying to implement an ‘if else’ function
I am trying to create function called “ifthen” in Matlab (it is being called in line 4 in the code above) which checks for the period of the object. If it is 1 then the object remains unchanged. If is not 1 then the obj.lag is subtracted from the original obj.
How should I implement this “ifthen” function so that it returns an object? In other words how do I implement an element wise “ifthen “function on an object?
I tried to do something like this but this does not work on an object
[FONT="]function[/FONT][FONT="] r = ifthis( condition, result1, result2)[/FONT]
[FONT="] error(nargchk(3,3,nargin));[/FONT]
[FONT="]if condition == ([/FONT][FONT="]obj.periods()==1[/FONT])
[FONT="] r = obj;[/FONT]
[FONT="]else[/FONT]
[FONT="] r = obj-obj.lag(-1);[/FONT]
[FONT="]end[/FONT]
[FONT="]end[/FONT]
<o:p></o:p>
<o:p>Any help would be appreciated</o:p>
<o:p></o:p>
<o:p>-Thanks
</o:p>