Skip to content

Instantly share code, notes, and snippets.

@JosephKJ
Created October 30, 2017 06:18
Show Gist options
  • Select an option

  • Save JosephKJ/9931a8fba92fe08e8f375a241d85d7b6 to your computer and use it in GitHub Desktop.

Select an option

Save JosephKJ/9931a8fba92fe08e8f375a241d85d7b6 to your computer and use it in GitHub Desktop.
Convert Small Object Dataset annotations from mat to csv
% Retrieving the data
data = load('SUN_small_obj_train.mat');
struct_arr = getfield(data, 'SUN_small_obj_train');
% Converting each row to a its corresponding csv
fileID = fopen('SUN_small_obj_train.csv','w');
[nrows,ncols] = size(struct_arr);
for row = 1:nrows
for col = 1:ncols
if isempty(struct_arr{row,col})
value = '_';
else
cell_value = struct_arr{row,col};
[r, c] = size(cell_value);
value = num2str(cell_value(1,:));
for inner_row = 2:r
value = strcat(value, ';',num2str(cell_value(inner_row,:)));
end
end
if col ~= ncols
fprintf(fileID,'%s,',value);
else
fprintf(fileID,'%s',value);
end
end
fprintf(fileID,'\n');
end
fclose(fileID);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment