如何将struct转换为单元格数组索引,我有一个struct,我希望将其转换为相对于data
&的单元数组索引。 label
。或者可能根据标签和数据直接指定单元格数组,以避免struct
使用。
我的代码:
for ii = 1:13
for jj = 1:numel(obj.R)
%R calc operatioiins
end
R=R(~cellfun('isempty',R)) ;
TData(ii).data=R;
TData(ii).label=cellfun(@(x) ['T' num2str(ii)] , num2cell(1:length(R))', 'UniformOutput', false);
end
输出:
TData(1).data
ans =
[10x3 double]
[10x3 double]
[10x3 double]
[10x3 double]
[10x3 double]
[10x3 double]
[10x3 double]
>> TData(1).label
ans =
'T1'
'T1'
'T1'
'T1'
'T1'
'T1'
'T1'
编辑1:
可能会更改以下内容: 实际输出:
[10x3 double]
[10x3 double]
[ 8x3 double]
[10x3 double]
[10x3 double]
[10x3 double]
[10x3 double]
'T1'
[ 5x3 double]
[ 5x3 double]
[ 5x3 double]
[ 5x3 double]
[ 5x3 double]
[ 5x3 double]
'T2'
[ 5x3 double]
[ 5x3 double]
[ 5x3 double]
[ 5x3 double]
[ 5x3 double]
[ 5x3 double]
'T3'
期望输出:
[10x3 double] 'T1'
[10x3 double] 'T1'
[ 8x3 double] 'T1'
[10x3 double] 'T1'
[10x3 double] 'T1'
[10x3 double] 'T1'
[10x3 double] 'T1'
答案 0 :(得分:0)
我不是100%,但尝试将其添加到for循环的末尾:
TDataCellArray{ii} = {{TData(ii).data}, {TData(ii).label}}