Let's say, i have matrix 6-by-1 matrix:
A=[ 1 --->labelling "1"
6 --->labelling "2"
3 --->labelling "3"
5 --->labelling "4"
-3 --->labelling "5"
10 ] --->labelling "6"
and
B=[5]
I want to write the code to compare each value in matrix A with B with condition ( If {A}<B---> I will pick up the index and the value from matrix A to make a new matrix)
Particurly: I have the number 1,3, -3 (in matrix A) is smaller than 5 (in matrix B) so I will have the result after compare condition as follows:
C=[ 1 --->labelling "1"
3 --->labelling "3"
-3 ] --->labelling "5"
and the labelling matrix D will be :
D=[ 1
3
5 ]
How to write a relationship between matrix A,B,C,D ?

2 件のコメント

KL
KL 2017 年 8 月 28 日
Read the documentation. Your questions have direct and simple answers right there.
Quincy Sproul
Quincy Sproul 2022 年 11 月 20 日
yeh read the entire documentation for a single question.

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

 採用された回答

Benjamin Imbach
Benjamin Imbach 2017 年 8 月 28 日
編集済み: Benjamin Imbach 2017 年 8 月 28 日

1 投票

check out the find function.
A = [1 6 3 5 -3 10]';
B = 5;
D = find(A<B); %(linear index)
C = A(D);

1 件のコメント

Jan
Jan 2017 年 8 月 28 日
編集済み: Jan 2017 年 8 月 28 日
This is even more efficient with "logical indexing": omit the "find".
C = A(A < B)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2017 年 8 月 28 日

コメント済み:

2022 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!