필터 지우기
필터 지우기

How to create an original matrix by using non zero value indices?

조회 수: 1 (최근 30일)
A = [1 0 0 0 1;
1 0 0 0 1 ;
1 0 0 0 0;
1 0 0 0 0;
1 0 0 0 0];
[R1 C1] = size(A); %% Size of A is 5 x 5
[X, Y] = find(A);
P = [X, Y];
P = [ 1 1;
2 1;
3 1;
4 1;
5 1;
1 5;
2 5];
[R2 C2] = size(P); %% Size of P is 7 x 2
How to create an original matrix (A) of the size 5 x 5 by using non zero value indices of variable P of the size 7 x 2 and remaining indices values are zero.

채택된 답변

yanqi liu
yanqi liu 2021년 2월 20일
sir, may be use the follows code
clc; clear all; close all;
A = [1 0 0 0 1;
1 0 0 0 1 ;
1 0 0 0 0;
1 0 0 0 0;
1 0 0 0 0];
%% Size of A is 5 x 5
[R1, C1] = size(A);
[X, Y] = find(A);
P = [X, Y];
P = [ 1 1;
2 1;
3 1;
4 1;
5 1;
1 5;
2 5];
%% Size of P is 7 x 2
[R2 C2] = size(P);
%% gen matrix
B = zeros(max(P(:,1)), max(P(:,2)));
loc = sub2ind(size(B), P(:,1), P(:,2));
B(loc) = 1;
disp(B)
isequal(A, B)
1 0 0 0 1
1 0 0 0 1
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
ans =
logical
1
>>
  댓글 수: 1
SUKUMAR NAGINENI
SUKUMAR NAGINENI 2021년 2월 20일
편집: SUKUMAR NAGINENI 2021년 2월 20일
Dear yanqi liu
Thank you so much sir for your help,
you can read the book 《计算机视觉与深度学习实战 , This textbook link is not available on any website in India. If possible, kindly share the link to the soft copy of the book.
Thanks & regards
Sukumar.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by