0

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

在此处输入图像描述

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

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

4

1 回答 1

1

您可以做的是struct2cell将其转换为二维元胞数组,然后您可以将第二列(objectBoundingBoxes字段)转换为字符串,使用mat2str该字符串将矩阵转换为字符串。然后,您应该能够将结果复制到 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);
于 2017-01-18T03:34:07.840 回答