Find a specific char in a cell and turn it into NaN
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
i need to plot some temperature data from a csv excel data. If the Sensors werent active, the value at this time says Error 4 or Error 6. Matlab cant really plot those values and my first attempt was to turn those values into NaN. But i cant really find anything to do this. I should mention, that im new to matlab and dont know more than the basics.
Thank you in advance!
댓글 수: 2
Stephen23
2021년 3월 15일
@Tobias Pfeifer: please upload a sample file by clicking the paperclip button.
답변 (2개)
DGM
2021년 3월 16일
편집: DGM
2021년 3월 16일
Let's say you have your sensor value as a cell vector -- but it's full of non-numeric garbage:
rawsensval={'3','5','Error 9000','53','24','Another Error','4345'};
sensvalnumeric=cell2mat(cellfun(@(s) {str2double(s)}, rawsensval))
Here, str2double() converts any non-numeric entries to NaN, giving you a simple numeric vector.
This is what I use in my own log processing scripts. There may be more elegant methods.
댓글 수: 0
Stephen23
2021년 3월 16일
편집: Stephen23
2021년 3월 16일
F = 'UmgebungsmessungDez.csv';
S = detectImportOptions(F, 'Delimiter',';', 'VariableNamingRule','preserve');
X = false(1,numel(S.VariableOptions));
X(4:end) = true; % specify which columns should be numeric
S = setvaropts(S, X, 'Type','double', 'DecimalSeparator',',');
S = setvaropts(S,'DATE', 'Type','datetime', 'InputFormat','dd.MM.yyyy');
T = readtable(F,S)
T(2110:2119,:) % the first few rows with number data
댓글 수: 2
Stephen23
2021년 3월 16일
@Tobias Pfeifer: please remember to accept the answer that helped you most! Accepting and voting for answers is the easiest way you can show your appreciation to the volunteers on this forum.
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!