rmfield / clear structur entry ?

1 Ansicht (letzte 30 Tage)
Max Müller
Max Müller am 12 Sep. 2014
Bearbeitet: Azzi Abdelmalek am 12 Sep. 2014
hey Guys, I have got a 1xn structure. Now i just want to write a code which can delete on column of a structure. For example:
A is structure with A.x / A.y /A.z This is a 1x5 structure. Now I want to make this a 1x4 structure by deleting the 3rd Column. So A(3) is gone and A(4) is now the new A(3) / A(5) is the new A(4)

Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 12 Sep. 2014
A=struct('x',num2cell(rand(1,5)),'y',num2cell(rand(1,5)),'z',num2cell(rand(1,5)))
A(3)=[]
  5 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 12 Sep. 2014
A=struct('UsedAmp',num2cell([1 2 3 4 5]),'OptimalAmp',num2cell([-1 2 3 4 -3]),'ClosestAmp',num2cell([0 2 3 4 -2]))
idx=[];
for u = 1:numel(A)
Check = A(u).UsedAmp + A(u).OptimalAmp + A(u).ClosestAmp;
if Check == 0;
idx(end+1)=u
end
end
A(idx)=[]
Azzi Abdelmalek
Azzi Abdelmalek am 12 Sep. 2014
Bearbeitet: Azzi Abdelmalek am 12 Sep. 2014
Or
A=struct('UsedAmp',num2cell([1 2 3 4 5]),'OptimalAmp',num2cell([-1 2 3 4 -3]),'ClosestAmp',num2cell([0 2 3 4 -2]))
A(squeeze(sum(cell2mat(struct2cell(A))))==0)=[]

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by