Data contains 2 columns (plan and T). However, plan contains some NaN. I would like to delete the NaN from plan and also its corresponding values in T so that the good data from columns plan and T will be of the same dimension

 채택된 답변

Guillaume
Guillaume 2015년 7월 15일

0 개 추천

Assuming data is an m x 2 matrix, it's simply:
Data(isnan(Data(:, 1)), :) = []
That is, find the nan in the first column of Data ( isnan(Data(:, 1))), and removes all the rows for which isnan is true ( Data(trueorfalse, :) = [])

댓글 수: 4

AbelM Kusemererwa
AbelM Kusemererwa 2015년 7월 15일
I save them as data for easy uploading. However, plan and T are separate in the workspace
Guillaume
Guillaume 2015년 7월 15일
편집: Guillaume 2015년 7월 15일
Well, it's still the same idea. Use the logical array returned by isnan to indicate which elements you want to remove in any of your variables:
todelete = isnan(plan); %find the nans
plan(todelete) = []; %remove them from plan
T(todelete) = []; %and remove them from T
AbelM Kusemererwa
AbelM Kusemererwa 2015년 7월 15일
편집: AbelM Kusemererwa 2015년 7월 15일
Please, after deleting I would want to give them different names. How do I store them separately after deleting?
Then you don't delete, you only copy the data you want to keep (everything that is not nan)
tokeep = ~isnan(plan); %use ~ for logical not
newplan = plan(tokeep);
newT = T(tokeep);

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

2015년 7월 15일

댓글:

2015년 7월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by