Info

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

Selectinh elements from an array

조회 수: 6 (최근 30일)
Hamed Davoudi
Hamed Davoudi 2020년 11월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
Suppose that I have a 20*20 array by the name of "S", which is distances between 20 stores. I have another variable, P, which is the produce those stores would have. User can choose which produce he wants to distribute and bey selecting every produce the number of available stores would be different. For example if I choose the Dairy, the only stores which are available are S=[4, 6, 9, 13, 17] and the other stores would be for Meat. How can I devide my S array into two different 15*15 and 5*5 arrays?
Thanks.

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 11월 1일
Check this code
S = rand(20);
selected_stores = [4, 6, 9, 13, 17];
idx1 = selected_stores;
idx2 = setdiff(1:size(S,1), selected_stores);
M1 = S(idx1, idx1); % 5x5
M2 = S(idx2, idx2); % 15x15

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

Community Treasure Hunt

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

Start Hunting!

Translated by