How can I discard some unwanted rows from a matrix in Matlab? -
i have matrix
a= [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16; 17 18 19 20]
i want calculation on matrix. not need rows. have discard of rows above matrix before doing calculation. after discarding 3 rows, have new matrix.
b= [1 2 3 4; 9 10 11 12; 17 18 19 20];
now have use b make other calculations. how can discard of unwanted rows matrix in matlab? suggestion helpful. thanks.
try this: (use when no. of rows keep lesser)
%// input a = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16; 17 18 19 20]; %// rows (1-3,5) wanted keep b = a([1:3, 5],:)
output:
b = 1 2 3 4 5 6 7 8 9 10 11 12 17 18 19 20
alternative: (use when no. of rows discard lesser)
%// rows 2 , 3 discarded a([2,3],:) = [];
output:
>> = 1 2 3 4 13 14 15 16 17 18 19 20
note: here (in alternate method), output replaces original a
. need a
if need afterwards. before discarding operation backup input matrix
%// input backed in b b = a;
Comments
Post a Comment