필터 지우기
필터 지우기

How to transform a vector to a matrix with same position ?

조회 수: 1 (최근 30일)
Safia
Safia 2022년 10월 29일
댓글: Safia 2022년 10월 30일
Hello everyone!
i want to ask you, if i have a matrix A in each row i have only one value , the rest are set to zero.Also i have a column vector V.
V =sum(A,2) but with removed elements.
I want to replace the value in A by the value in V at the same positions.
this is an example :
A=[100 0 0 0 0 0
0 50 0 0 0 0
0 0 0 20 0 0
0 0 0 0 30 0
0 0 0 0 0 80]
here the removed element in row 2 (50).
So V is the follow:
V=[100
20
30
80]
Now i want to replace A by elements in V.
the required result is :
A1=[100 0 0 0 0 0
0 0 0 20 0 0
0 0 0 0 30 0
0 0 0 0 0 80]
How can i do that?

채택된 답변

Matt J
Matt J 2022년 10월 30일
A=A( ismember(sum(A,2),V) ,:)

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by