我有以下代码matlab
并尝试从结构中删除一个元素:
function test()
C = struct;
C.(sprintf('Ck')) = [1 6 8 9; 8 6 9 7; 7 6 67 6; 65 7 8 7];
ck_length = length(C.(sprintf('Ck')));
for i=1:ck_length
if C.(sprintf('Ck'))(i)> 10
cleared = rmfield(C.(sprintf('Ck')), C.(sprintf('Ck'))(i));
end
end
end
但是,当我运行程序时,出现如下所示的错误:
>> test
??? Error using ==> rmfield at 19
S must be a structure array.
Error in ==> test at 89
cleared = rmfield(C.(sprintf('Ck')), C.(sprintf('Ck'))(i));
我该如何解决这个问题?
谢谢。