how to remove an entire column in a cell array

45 Ansichten (letzte 30 Tage)
Alexya
Alexya am 26 Okt. 2022
Beantwortet: David Hill am 26 Okt. 2022
I have a cell array of ca and I need to be able to remove an entire column. So far I am able to delete the last column 'Final', but not sure how to delete the middle columns since its a mixed cell array of char and doubles.
ca = {'Name','Test1','Test2','Test3','Final';
'A', 70 , 80 , 100, 99;
'B', 30 , 90, 95, 90;
'C', 100, 70, 85, 90}
newCa = ca(:,2:end)

Akzeptierte Antwort

Voss
Voss am 26 Okt. 2022
ca = {'Name','Test1','Test2','Test3','Final';
'A', 70 , 80 , 100, 99;
'B', 30 , 90, 95, 90;
'C', 100, 70, 85, 90};
% delete the third column, say:
ca(:,3) = []
ca = 4×4 cell array
{'Name'} {'Test1'} {'Test3'} {'Final'} {'A' } {[ 70]} {[ 100]} {[ 99]} {'B' } {[ 30]} {[ 95]} {[ 90]} {'C' } {[ 100]} {[ 85]} {[ 90]}

Weitere Antworten (1)

David Hill
David Hill am 26 Okt. 2022
ca = {'Name','Test1','Test2','Test3','Final';
'A', 70 , 80 , 100, 99;
'B', 30 , 90, 95, 90;
'C', 100, 70, 85, 90};
newCa=ca;newCa(:,3)=[]
newCa = 4×4 cell array
{'Name'} {'Test1'} {'Test3'} {'Final'} {'A' } {[ 70]} {[ 100]} {[ 99]} {'B' } {[ 30]} {[ 95]} {[ 90]} {'C' } {[ 100]} {[ 85]} {[ 90]}

Kategorien

Mehr zu Multidimensional Arrays 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