table / timetable - removing zero columns
조회 수: 5 (최근 30일)
이전 댓글 표시
My answer is:
function pTable = aRemoveZeroTableColumns(primersTable)
%
%
%
pTable = primersTable;
indexes = [];
for i = 1:numel(primersTable.Properties.VariableNames)
column = primersTable{:,i};
if all(column == 0)
indexes = [indexes, i];
end
end
pTable(:,indexes) = [];
end
Is there a shorter solution?
댓글 수: 0
채택된 답변
dpb
2018년 5월 20일
편집: dpb
2018년 5월 20일
Presuming since you're comparing all to zero, that all elements of the table are numeric, then simply
pTable=primersTable(:,~all(primersTable{:,:}==0));
will do the dirty...simple example--
>> t=table(zeros(5,1),rand(5,1),zeros(5,1)); % sample table w/ zero columns
>> t(:,~all(t{:,:}==0))
ans =
5×1 table
Var2
_______
0.54
0.93709
0.66096
0.39466
0.25899
>>
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!