I want to create a code that tells me the location of the number I entered whenever the function varies from trial to trial.

조회 수: 1 (최근 30일)
a = randperm(5);
b = [1 2 3 4 5];
matrix = b(a)
number = input('Please enter a number');
number = position % A code that tells you the location of the number you entered.
% But I think this code is wrong.
if position == 1
matrix(:,1) = [ ]
elseif position == 2
matrix(:,2) = [ ]
elseif position == 3
matrix(:,3) = [ ]
elseif position == 4
matrix(:,4) = [ ]
elseif position == 5
matrix(:,5) = [ ]
end
I would like to create a matrix that is missing if I enter one of the 1-5 numbers in the above random function.
For example, if I enter 2 in 3 2 4 5 1 matrix, 3 4 5 1 matrix must be created
So I want to know which of the random functions 3 2 4 5 1 is located at which number of times I entered.
The problem is that it is a random function, so the matrix varies from trial to trial.
So I want to create a code that tells me the location of the number I entered whenever the function varies from trial to trial.
please help me sir

채택된 답변

Bhaskar R
Bhaskar R 2020년 2월 14일
편집: Bhaskar R 2020년 2월 14일
Am I correct?
number = input('Please enter a number'); % input number
matrix(number) = []; % delete corresponding number position element from the matrix

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by