function [] = WriteStruct(structure_array,filename)

%// Extract field data
% fields = repmat(fieldnames(structure_array), numel(structure_array), 1);

fields = fieldnames(structure_array);
values = struct2cell(structure_array);

%// Convert all numerical values to strings
% idx = cellfun(@isnumeric, values); 
values = cellfun(@num2str, values, 'UniformOutput', 0);

%// Combine field names and values in the same array
C = {fields{:}; values{:}};

%// Write fields to CSV file

fid = fopen([filename '.txt'], 'w+');
fmt_str = repmat('%s, %s\n', 1, size(C, 2));
fprintf(fid, [fmt_str(1:end - 1), '\n'], C{:});
fclose(fid);