Unknown operation performed.

3 ビュー (過去 30 日間)
Yulia M
Yulia M 2019 年 11 月 21 日
編集済み: Yulia M 2019 年 11 月 22 日
Hi,
I am new to MATLAB. the following is my code I am unable to understand
the operation perfromed B = S(A); and C = S(~A);
B has size 15x1 double
C has size 285x1 double
S is 20x15 double
A is 20x15 logical
my question is what operation has been performed in B and C and how did they get that size?
Please help me understand this!
clear all;
clc;
A = false( 20,9 );
sP = generate_pilots( 15 , 4, 'deterministic' );
G = [4:4:11 12:4:21]';
H = (2:7:20)';
A( G, H-1 ) = true;
S = zeros( size(A) );
B = S(A);
C = S(~A);
D = sP(1:15);
S( A ) = sP(1:15);
Regards,
Gnanesh

採用された回答

Philippe Lebel
Philippe Lebel 2019 年 11 月 21 日
編集済み: Philippe Lebel 2019 年 11 月 21 日
This is called logical (or boolean) indexing.
Your A matrix is filled with booleans.
B is now a vector that has all the elements of S that correspond to the same indexes as the Ones in A.
C is now a vector that has all the elements of S that correspond to the same indexes as the Zeros in A.
a = logical([1 0 0 1; 0 0 1 0])
s = [1,2,3,4;5,6,7,8]
s(a)
ans =
1
7
4
  3 件のコメント
Philippe Lebel
Philippe Lebel 2019 年 11 月 21 日
編集済み: Philippe Lebel 2019 年 11 月 21 日
No, it has to be filled with only booleans.
you can make it by different means:
1: automatically
mat = [1,2,3,4,5];
a = mat<3
a =
1 1 0 0 0
2:manually
a = [true true false flase true];
%or
a = logical([1 1 0 0 1]);
For the sizes of the matrix B and C, take the following example:
A = logical([1 0 0 1; 0 0 1 0]);
S = [1,2,3,4;5,6,7,8];
B = S(A)
B =
1
7
4
B is a 3x1 vector because there are only 3 Ones in A. The logical indexing fetches only 3 elements in S to put them in B.
Yulia M
Yulia M 2019 年 11 月 22 日
編集済み: Yulia M 2019 年 11 月 22 日
Hi Philippe,
I got it. Thank you very much for your valuable time.
regards,

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by