How to replace/delete some elements of a Matrix to a certain value

조회 수: 1 (최근 30일)
hasan haider
hasan haider 2019년 10월 23일
댓글: Steven Lord 2019년 10월 23일
Hello everyone,
I have a matrix of 2799x7 matrix and i want to delete 10% of the data points or individual cells randomly. Or replace 10% of the data sets to zero. The size of the matrix should remain the same after the operation.
  댓글 수: 1
Steven Lord
Steven Lord 2019년 10월 23일
You can't delete individual elements of a numeric array in MATLAB to leave "holes" in the array. Guillaume listed how to replace a certain number of elements with 0's, but depending on what you're going to do with this data afterwards replacing them with NaN or missing instead of 0 may be more useful.
Generally 0 is more likely to be a valid data value than NaN. Because of this using the missing data functions (ismissing, rmmissing, fillmissing, standardizeMissing) on your 0-filled data may remove real data that happened to be 0 before you "deleted" 10% of your data points.

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

채택된 답변

Guillaume
Guillaume 2019년 10월 23일
편집: Guillaume 2019년 10월 23일
yourmatrix(randperm(numel(yourmatrix), numel(yourmatrix) * 0.1)) = 0; %replace 1/10th of the elements chosen at random by 0
  댓글 수: 2
hasan haider
hasan haider 2019년 10월 23일
Its giving an error. Are you sure that there will be = ?
Guillaume
Guillaume 2019년 10월 23일
It was missing a closing bracket. Fixed now.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by