필터 지우기
필터 지우기

Info

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

code to form a matrix by selecting few elements randomly from another matrix

조회 수: 1 (최근 30일)
nishitha
nishitha 2014년 10월 10일
마감: MATLAB Answer Bot 2021년 8월 20일
i have a matrix with me which is a rectangular matrix of size 14*13. now i need to select some elements randomly from this matrix and form another matrix of size 14*13. can u give me the code for this as soon as possible.

답변 (1개)

Image Analyst
Image Analyst 2014년 10월 12일
Here's one possible situation. I'd be a mind reader though if I happened to pick exactly the scenario you were thinking of:
matrix1 = rand(14,13) % Sample data.
matrix2 = zeros(14, 13); % Initialize to all zeros.
% Get 20 random locations to haul over to matrix2.
numberToTransfer = 20
randomLocations = randperm(numel(matrix1), numberToTransfer);
% Transfer them over from matrix1 to the same locations in matrix2.
matrix2(randomLocations) = matrix1(randomLocations)

이 질문은 마감되었습니다.

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by