我有下面的MATLAB struct,有两个字段:

我正尝试将其分成两列导出到Excel中(或者导出到只有第二列objectBoundingBoxes的记事本)。当字段维度是2x4或1x4时,它会显示分号分隔值(这是我想要的),但当维度是3x4或更高(最多6x4)时,它只会写入3x4双精度值,而不是将它们写成分号分隔值。因此,现在当我将列复制粘贴到Excel中时,它只写入3x4双精度值而不是值。
有没有办法在Matlab的变量显示窗口中显示分号分隔值而不是3x4双精度值?如果不是,那么您能否建议将这些值导出为1,2,3,4;5,6,7,8;9,0,1,2.....
发布于 2017-01-18 11:34:08
您可以做的是使用struct2cell将其转换为2D单元格数组,然后可以使用mat2str将第二列( objectBoundingBoxes字段)转换为字符串,这将把矩阵转换为字符串。然后,您应该能够将结果复制到Excel中
% Create some pseudo-data to test
your_struct = struct('imageFilename', {'file1', 'file2', 'file3'}, ...
'objectBoundingBox', {1, rand(4,2), 2});
% Convert your struct into an N x 2 cell array
C = squeeze(struct2cell(your_struct)).';
% Convert the second column to strings which represent the matrices
C(:,2) = cellfun(@mat2str, C(:,2), 'UniformOutput', false);https://stackoverflow.com/questions/41710874
复制相似问题