I have been assigned to run these codes and report what are they for. I'm good up to the 8th line. After that i'm lost and don't know what the last 3 lines do. I'll appreciate it if someone help me and explain what they do.
Thanks
a=rand(5);
b=a;
m=size(a,2);
x=1:m;
y=1:m;
xx=x'*ones(1,m);
yy=(y'*ones(1,m))';
c=xx==yy;
b(c)=0
c=xx.^2>yy;
a(c)=0

 採用された回答

Henry Tran
Henry Tran 2020 年 12 月 10 日
編集済み: Henry Tran 2020 年 12 月 10 日

0 投票

Hi,
b(c)=0 %sets all values of b to 0, which are along the 1 of c
c=xx.^2>yy; %checks if the value of "xx.^2" is greater than the values in yy. If it is true then it returns as 1.
a(c)=0 --> %same principle as b(c)=0
I hope it answers your question.

4 件のコメント

javad hemati
javad hemati 2020 年 12 月 10 日
Thank you <3
javad hemati
javad hemati 2020 年 12 月 10 日
about the b(c)=0, what do you mean by '' which are along the 1 of c ''. I didn't catch that part
the cyclist
the cyclist 2020 年 12 月 10 日
I found the phrasing confusing, too. Here is an example. Suppose b and c are
b = [2 3 5 7 11]
c = [1 0 1 1 0];
Then b(c) will be
[2 5 7]
In other words, b(c) picks out the elements of b where c is equal to 1.
javad hemati
javad hemati 2020 年 12 月 10 日
Thank you. got it now

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

その他の回答 (1 件)

the cyclist
the cyclist 2020 年 12 月 10 日

0 投票

This documentation about indexing with logical values might help you understand.

カテゴリ

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

製品

リリース

R2016a

質問済み:

2020 年 12 月 10 日

コメント済み:

2020 年 12 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by