how would you actually render the structure in csv? you cannot make a direct map of field names as entries in the first row, because the matrices have incompatible sizes. So, in this example, you will need to: 1. enter some columns for own_dummies and 2. expand cdindex.
So, you can write a shell to make the matrices themselves compatible and write the columns to a file yourself. something along (untested, conceptual) lines
function saveData(filename, data, type) % at first bring struct data to sensible format if strcmp(type)='my_mat_type' data.own_dummies2 = data.own_dummies[2,:]; % split into seperate columns %... data.own_dummies26 = data.own_dummies[26,:]; data.own_dummies = data.own_dummies[1,:]; data.cdindex = [data.cdindex -ones(1,2217-length(data.cdindex)]; % pad any missing values as -1 end; FD = fopen(filename, 'w'); %todo did it open? fields = fieldnames(data); nfields = length(fields); % create column name values columns = strcat(strcat(fields,',')); % creates string = col1,col2,...coln, columns = columns(1:length(columns)-1); %remove trailing comma CRNL = char([10 13]); % or so % print columns and newline fprintf(FD,strcat(columns,CRNL)); dataout = cell2mat(struct2cell(data)); % use your method to write the data to the file fclose(FD);
Naturally, you can also simply separate the individual fields into separate files, where the field name is contained in the file name, which can be simpler, generally speaking.
Filou source share