Transfer variables within function with different properties.
Afficher commentaires plus anciens
Hi,
I wrote the following class code:
classdef Copy_of_getPortRawData
properties
PortMembers
PortWeights
end
methods
function obj=getPortRawData(c,PortID,Dates)
obj=getPortMembers(obj,c,PortID,Dates);
obj=getPortWeights(obj,Dates);
end
% 1)
function obj=getPortMembers(obj,c,PortID,Dates)
% Define input parameters
portField={'PORTFOLIO_MWEIGHT'};
override={'REFERENCE_DATE'};
nDates=size(Dates,1);
rawPortData=cell(nDates,1);
% start downloading raw portfolio data
for r=1:nDates
rawPortData{r}=portfolio(c,PortID,portField,override,datestr(Dates(r,1),'yyyymmdd'));
% simplify data storage structure and delete first row
rawPortData{r}=rawPortData{r,1}.PORTFOLIO_MWEIGHT{1,1};
% find unique portfolio members
if r==1
obj.PortMembers=rawPortData{r}(:,1);
else
obj.PortMembers=union(obj.PortMembers,rawPortData{r}(:,1),'sorted');
end
end
end
% 2)
function obj=getPortWeights(obj,Dates)
% construct matrix of weights for each portfolio member and each date
nPortMembers=size(obj.PortMembers,1);
obj.PortWeights=zeros(nDates,nPortMembers);
nDates=size(Dates,1);
for r=1:nDates
ind=ismember(obj.PortMembers,rawPortData{r}(:,1));
obj.PortWeights(r,ind)=transpose(cell2mat(rawPortData{r}(:,2)));
end
end
end
end
My question refers to the code after the line with text % 2)
How does the code look like if I want to work with the variable "rawPortData" coming from the function under the line % 1)?
thanks a lot in advance for your reply.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Elementary Math dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!