필터 지우기
필터 지우기

Convert cell array to numerical array while keeping format and removing NAN

조회 수: 6 (최근 30일)
I have a cell array comprised of a single column and many rows. Some rows have 'NAN' and some have numbers such as 42.54. I want to extract the data from this cell array while keeping the format. I also want to get rid of the NAN values. I don't care if the NAN values are removed completely or replaced with 0. A for loop was ineffective and took to long. I tried isnan and isfinite, but they did not seem to remove the nan. I also tried cell2mat but that removes the format of my column and puts every character together. My cell looks something like this:
'NAN'
'NAN'
'NAN'
'NAN'
'NAN'
'NAN'
'NAN'
'43.16'
'43.16'
'43.1'
'43.1'
'43.08'
'43.08'
'43.06'
'NAN'
'NAN'
'NAN'
'43.1'
'43.1'
'43.08'
'43.08'
However there are thousands of data points and hundreds of 'NAN' scattered throughout.
Thank you

채택된 답변

Walter Roberson
Walter Roberson 2015년 10월 1일
T = str2double(YourCellArray);
T(isnan(T)) = [];

추가 답변 (1개)

Oscar Hernandez
Oscar Hernandez 2015년 10월 2일
Awesome, thank you Walter Roberson

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by