logic question regarding two vectors

The two vectors, x=[0, -4, 7, 0, -1, 2], y=[1, -4, 8, 0, 1, 6] are given. Explain how matlab could reutrn...z = x and (not y)

回答 (2 件)

David Hill
David Hill 2022 年 9 月 8 日

0 投票

Really have no idea what you are asking.... just guessing
x=[0, -4, 7, 0, -1, 2];
y=[1, -4, 8, 0, 1, 6];
z=min(x,y)
z = 1×6
0 -4 7 0 -1 2

8 件のコメント

Sami Ahmed
Sami Ahmed 2022 年 9 月 8 日
im not understanding this HW question ...
David Hill
David Hill 2022 年 9 月 8 日
x=[0, -4, 7, 0, -1, 2];
y=[1, -4, 8, 0, 1, 6];
z=x&~y
z = 1×6 logical array
0 0 0 0 0 0
z=(x&y)|(~x)
z = 1×6 logical array
1 1 1 1 1 1
Note, x and y vectors can be converted to logical vectors: anynumbers not zero are logical 1, otherwise logical zero
logical(x)
ans = 1×6 logical array
0 1 1 0 1 1
logical(y)
ans = 1×6 logical array
1 1 1 0 1 1
Walter Roberson
Walter Roberson 2022 年 9 月 8 日
This was obviously a homework question though...
Sami Ahmed
Sami Ahmed 2022 年 9 月 8 日
okay...?
Sami Ahmed
Sami Ahmed 2022 年 9 月 8 日
@David Hill thank you
Walter Roberson
Walter Roberson 2022 年 9 月 8 日
We discourage volunteers from giving complete code for homework questions, as we find that when we do that, often the people do not learn the techniques, and instead mostly copy the answer given. We encourage the volunteers to instead answer in ways that teach the concepts, leaving the people asking the questions to apply the concepts to arrive at the answer.
Sami Ahmed
Sami Ahmed 2022 年 9 月 8 日
i understand, ur like a TA then. I will try to rephrase my questions better.
Sami Ahmed
Sami Ahmed 2022 年 9 月 8 日
@David Hill @Walter Roberson i was entering z=x&~=y instead of z=x&~y. this was my isse thank you

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

Walter Roberson
Walter Roberson 2022 年 9 月 8 日

0 投票

The "or" operation for vectors is written as the | operator.
The "and" operation for vectors is written as the & operator.
The "not" operation for vectors is written as the ~ operator.
Note that for the purpose of MATLAB, a value is considered true if it is non-zero (except that it is an error to apply logical tests directly to NaN values.)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2022a

質問済み:

2022 年 9 月 8 日

コメント済み:

2022 年 9 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by