Boolean help with arrays

8 ビュー (過去 30 日間)
Nathen Eberhardt
Nathen Eberhardt 2020 年 3 月 4 日
コメント済み: Nathen Eberhardt 2020 年 3 月 4 日
I need help with some boolean statements. How do i create a boolean statement with an array. So pretty much i created a 2 3x3 arrays and I need to create a boolean statement to :
A = 3X3 Array
B = 3x3 array
C = 2x3 array
D = 2x3 array
A single boolean (1 or 0), indicating whether or not A contains the number 7
• A single boolean (1 or 0), indicating whether or not D is ALL zeros •
A single boolean (1 or 0), indicating whether or not A and C are equal •
A single boolean (1 or 0), indicating whether or not A and B are equal
  2 件のコメント
James Tursa
James Tursa 2020 年 3 月 4 日
What have you done so far? What specific problems are you having with your code? Are you supposed to code this with loops or are you allowed to use MATLAB supplied functions?
Nathen Eberhardt
Nathen Eberhardt 2020 年 3 月 4 日
I tried these so far
%if A contains the number 7
Find_7 = A(find(7))
% A single boolean (1 or 0), indicating whether or not A and C are equal
Equal_things = isequal(A,C)
%A single boolean (1 or 0), indicating whether or not A and B are equal
Equal_things2 = isequal(A,B)
%finding if all numbers in D are 0
All_zeros = D(all(0))
The Last one, finding if all numbers are 0 in D, shows >> []
D is = [0,0,0;0,0,1]

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

採用された回答

James Tursa
James Tursa 2020 年 3 月 4 日
You have incorrect syntax. First a big hint: A(:) turns A into a column vector containing all of the elements in a column ordered manner. So you can operate on A(:) to see if any or all of its elements meets a condition. E.g.,
all( A(:) < 4 ) would test to see if all elements of A are less than 4
any( A(:) == 0 ) would test to see if any element of A is equal to 0
Etc.
  1 件のコメント
Nathen Eberhardt
Nathen Eberhardt 2020 年 3 月 4 日
Thank you so much!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by