필터 지우기
필터 지우기

how can i reshape an indexed vector

조회 수: 1 (최근 30일)
fadams18
fadams18 2020년 11월 2일
댓글: fadams18 2020년 11월 2일
Hello,
I have the following problem:
Q % e.g. 300 x 300 matrix
M % e.g. 300 x 300 matrix
omega=find(Q); % omega becomes a 86567x1 vector
b= M(omega);% b is also a 86567x1 vector
Is there a way to reshape b to have the same dimension as Q?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 2일
편집: Ameer Hamza 2020년 11월 2일
Q has 90000 elements, whereas b has 86567 elements. Direct reshaping is not possible. I guess you are trying to do something like this
Q % e.g. 300 x 300 matrix
M % e.g. 300 x 300 matrix
b = M.*Q
It an element in Q is zero, then it will multiply the corresponding element in M with 0 too.
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 11월 2일
Ok, In that case, you can do something like this
Q = randi([0 1], 300); % e.g. 300 x 300 matrix
M = rand(300); % e.g. 300 x 300 matrix
omega=find(Q); % omega becomes a 86567x1 vector
b = M(omega);% b is also a 86567x1 vector
% apply your algorithm on b vector
B = zeros(size(Q));
B(Q~=0) = b;
B has same size as Q.
fadams18
fadams18 2020년 11월 2일
Thanks a lot man. I guess its my algorithm that has issues. your fix makes sense. only i didnt get the desired image i wanted. Thanks all the same.

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

추가 답변 (1개)

KSSV
KSSV 2020년 11월 2일
Whn you use find you will get the global indices in the form of column array...YOu can use logical indexing, so that you can have your matrix dimensions intact with 1 where condition is obeyed and 0 where condition is not.
omega = Q~=0;
  댓글 수: 1
fadams18
fadams18 2020년 11월 2일
This could be useful in future. Now i understand how the find works. thanks!

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by