views:

81

answers:

0

How to convert variable of 'struct' type to a matrix in Matlab?

How do we convert the q_yearly_w, in the code below, which is of type 'struct' to a matrix with which we can perform normal mathematical operations?

%# open the file
fid = fopen(Reportq_rwo);

%# read it into one big array, row by row
fileContents = textscan(fid,'%s','Delimiter','\n');
fileContents = fileContents{1};
fclose(fid); %# don't forget to close the file again

%# find rows containing TABLE NUMBER
wellStarts = strmatch('TABLE NUMBER',fileContents);
nWells = length(wellStarts);

%# loop through the wells and read the numeric data
wellData = cell(nWells,2);
wellStarts = [wellStarts;length(fileContents)];

for w = 1:nWells
    %# read lines containing numbers
    tmp = fileContents(wellStarts(w)+6:wellStarts(w)+6+T-1);
    %# convert strings to numbers
    tmp = cellfun(@str2num,tmp,'uniformOutput',false);
    %# catenate array
    tmp = cat(1,tmp{:});
    %# assign output
    q_yearly_w(:,w)=tmp(:,2);
end