필터 지우기
필터 지우기

How to remove rows that contains other than decimal value in a column?

조회 수: 2 (최근 30일)
Haritha
Haritha 2019년 4월 29일
편집: Adam Danz 2019년 4월 29일
Hi, in column 3 of table1 contains both decimal values and String values , i need to make the entire row as empty that contains other than decimal values. I am attaching sample code here.
d1= {'0.1';'0.2';'0.3';'0.4';'0.5'};
a1 = {'fix';'run';'debug';'continue';'break'};
b1 = {'70';'72';'70';'50';'C'};
c1 = {'DAC';'DAC';'DAC';'DAC';'DAC'};
table1=[d1,a1,b1,c1]
for i = 1:size(table1)
table1{i,3} =str2num( table1{i,3})
if table1{i,3}==[0]
table1{i,:}=[]
end
end
Please help me if anyone knows...
  댓글 수: 1
Adam Danz
Adam Danz 2019년 4월 29일
Actually, all of the elements of your table contain string values. Did you mean to convert the numeric-strings ( '70' ) to numeric ( 70 )?

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

채택된 답변

Adam Danz
Adam Danz 2019년 4월 29일
편집: Adam Danz 2019년 4월 29일
Replace rows of table1 that contain a number in string format in column 3 with empties:
isStr = isnan(str2double(table1(:,3)));
table1(isStr,:) = {[]};
If you want to convert the numeric-strings ( '70' ) to numeric ( 70 ),
isNum = ~isnan(str2double(table1));
table1(isNum) = num2cell(str2double(table1(isNum)));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by