将具有多维值的 Matlab 变量结构导出到 Excel

Exporting a Matlab Variable Struct having multi dimension values to Excel

我有以下带有两个字段的 MATLAB struct

我试图将其导出到 Excel 的两列中(或导出到只有第二列 objectBoundingBoxes 的记事本)。当字段尺寸为 2x4 或 1x4 时,它显示分号分隔值(这是我想要的),但是当尺寸为 3x4 或更高(最多 6x4)时,它只写 3x4 double 而不是将它们写为分号分隔值。所以现在当我将列复制粘贴到 Excel 时,它只写 3x4 double 而不是值。

有没有办法在 Matlab 的变量显示 window 中显示分号分隔值而不是 3x4 double?如果没有,那么您能否建议另一种将这些值导出为 [1,2,3,4; 5,6,7,8; 9,0,1,2....].

您可以使用 struct2cell 将其转换为二维元胞数组,然后您可以使用 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);