我有一个结构:
p=struct('exponent',{1,2,2,4},'coeff',{2,5,6,7})
我正在尝试删除指数字段(2)和coeff
字段(6)的第三个元素,以便它们不这样的空白空间:
p=struct('exponent',{1,2,[],4},'coeff',{2,5,[],7})
但是变成了像这样的长度为3的结构
p=struct('exponent',{1,2,4},'coeff',{2,5,7})
我不确定该怎么做。
答案 0 :(得分:0)
简单方法:
p(3) = [];
另一种方法,允许更大的灵活性(例如,你可以删除第三个指数和第二个系数,如果有意义的话):
e = [p.exponent]; %// convert to vector
e = num2cell(e([1:2 4:end])); %// remove third and convert to cell array
c = [p.coeff];
c = num2cell(c([1:2 4:end])); %// or remove any other than the third here
p = struct('exponent',e,'coeff',c) %// recreate p