how to skip the index of array

조회 수: 25 (최근 30일)
Shehab Tarek
Shehab Tarek 2020년 5월 27일
답변: Tommy 2020년 5월 27일
i have the index array =[1,2,1,2,4]
the output matrix =[2,3,4,5,6]
the second output matrix=[1,3,4,5,6]
the third output matrix=[2,3,4,5,6]
and so on

채택된 답변

Tommy
Tommy 2020년 5월 27일
Alternatively,
idx = [1,2,1,2,4];
N = 6; % max index
out = repmat(1:N, numel(idx), 1)';
out = reshape(out(out ~= idx), [], numel(idx))';
The rows in out are your outputs:
>> out
out =
2 3 4 5 6
1 3 4 5 6
2 3 4 5 6
1 3 4 5 6
1 2 3 5 6

추가 답변 (1개)

Stanislao Pinzón
Stanislao Pinzón 2020년 5월 27일
Maybe something like this:
A = [1,2,1,2,4];
for i=1:length(A)
B=1:6;
B(A(i))=[];
disp(B);
end

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by