Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

replace some elements to zero if they are not NaN

조회 수: 1 (최근 30일)
summyia qamar
summyia qamar 2018년 8월 5일
마감: summyia qamar 2018년 8월 5일
I have a matrix
A=[2 3 NaN NaN 3 NaN NaN 9 9 9;
3 4 NaN NaN 3 NaN NaN 9 5 8;
1 2 NaN NaN 4 NaN NaN 8 7 9]
I want to replace 30% of non zero elements in each row to 0.. for example, 30% of non-zero elements is 2.I want to replace each row with 2 zeros
A=[0 3 NaN NaN 3 NaN NaN 9 0 9;
3 4 NaN NaN 0 NaN NaN 9 0 8;
1 0 NaN NaN 4 NaN NaN 8 0 9]
how can I do this? I have done some but for that case no Nan is available in matrix but in this case I want that Nan remains and rest is replaced. Please guide.
  댓글 수: 2
jonas
jonas 2018년 8월 5일
편집: jonas 2018년 8월 5일
30% of 6 is not 2. Do you round off any decimals? Also, do you want to select those two numbers randomly?
Jan
Jan 2018년 8월 5일
편집: Jan 2018년 8월 5일
If no NaNs are available, you want to keep the NaNs and the rest is replaced? This sounds confused. What exactly are 30%, if the number of columns is not a multiple of 10?

답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by