필터 지우기
필터 지우기

matrix indexcing in compare with two matrices

조회 수: 1 (최근 30일)
fatema saba
fatema saba 2015년 1월 17일
댓글: fatema saba 2015년 1월 17일
Hello
I have 3 matrices:
m_z=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0]
m_y=[19 6 21 16 5 17 3 25 9 20 8 24 15 11 12 4 23 7 14 13 18 2 1 10 22]
m_x=[9 13 14 17 1 2 3 8 21 6 11 12]
I want to run
A=m_z(m_y)
except about the numbers that are in m_x. about these numbers, elemnts of matrix A must be zero.
Thank you very much

채택된 답변

Guillaume
Guillaume 2015년 1월 17일
Wouldn't this do what you want:
m_z(m_x) = 0; %set elements m_x of m_z to 0 so when they're indexed by m_y they return 0
A = m_z(m_y);
  댓글 수: 5
Guillaume
Guillaume 2015년 1월 17일
You must have a fairly old version of matlab, then. The two argument version of randperm has been available since R2011b. Just use randperm with 1 argument and use the first 6 elements.
pick = randperm(numel(validindices);
pick = pick(1:6);
fatema saba
fatema saba 2015년 1월 17일
Thank you for your kindness

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by