Eliminating columns from the matrix

조회 수: 2 (최근 30일)
Karanvir singh Sohal
Karanvir singh Sohal 2021년 4월 5일
댓글: Karanvir singh Sohal 2021년 4월 5일
Hello!
I have matrix containing string data and nums.
a=[0 12 13;0 5 4;0 9 6;0 8 9]'
b={'a'; 'b'; 'c'}
fprintf('%5s %5s %5s\n', b{:}); fprintf('%5d %5d %5d\n', a);
output:
a b c
0 12 13
0 5 4
0 9 6
0 8 9
I want to eliminate the columns which contains all the elements as "0" and also first string corosponding to "0" column.
required output:
b c
12 13
5 4
9 6
8 9

채택된 답변

KSSV
KSSV 2021년 4월 5일
a=[0 12 13;0 5 4;0 9 6;0 8 9]
a = 4×3
0 12 13 0 5 4 0 9 6 0 8 9
idx = any(a)==0 ;
a(:,idx)=[]
a = 4×2
12 13 5 4 9 6 8 9
  댓글 수: 3
KSSV
KSSV 2021년 4월 5일
b={'a'; 'b'; 'c'} ;
b(idx) =[]
Karanvir singh Sohal
Karanvir singh Sohal 2021년 4월 5일
Thanks @KSSV

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by