フィルターのクリア

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

1 回表示 (過去 30 日間)
SUKUMAR NAGINENI
SUKUMAR NAGINENI 2021 年 2 月 19 日
編集済み: SUKUMAR NAGINENI 2021 年 2 月 20 日
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 Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by