フィルターのクリア

How to write comments defining the elements in a 2d array?

1 回表示 (過去 30 日間)
catarina
catarina 2012 年 1 月 4 日
Hello,
I want to write text defining the elements of my matrice but can't figure out how to do it. I need to write a matrice that has element 1 if An <= Yj <= An+1 ; 0 otherwise.
I don't know how to put these instruction about the elements into the matrice. Hope I'm making sense!
Anyone that can help?
Thanks
Catarina

回答 (1 件)

Dr. Seis
Dr. Seis 2012 年 1 月 4 日
>> Yj = rand(3,4)
Yj =
0.5447 0.4239 0.1753 0.2433
0.2167 0.8710 0.1654 0.1209
0.8463 0.2685 0.3614 0.5910
>> Zj = (Yj>=0.3).*(Yj<=0.7)
Zj =
1 1 0 0
0 0 0 0
0 0 1 1
Note the ".*" used for element-by-element multiplication. Just substitute the 0.3 and 0.7 for your values associated with An and An+1.
  3 件のコメント
Dr. Seis
Dr. Seis 2012 年 1 月 5 日
It should work. I just showed an example of Yj (since I don't know what those values actually are), but as long as you substitute "An" and "An+1" for "0.3" and "0.7", respectively, then you should get the correct result.
Fnj = (An<=Yj).*(Yj<=(An+1))
You did want Fnj to be the same sized matrix as Yj, right?
Dr. Seis
Dr. Seis 2012 年 1 月 5 日
Also, you can copy my example above and paste into your Matlab command window to see how things work. For example:
A = (Yj>=0.3)
will produce a logical matrix the same size as Yj, but will have values of 1 for elements of Yj that are >= to 0.3 and values of 0 otherwise.
B = (Yj<=0.7)
will produce a logical matrix the same size as Yj, but will have values of 1 for elements of Yj that are <= 0.7 and values of 0 otherwise. By multiplying each element in A by the corresponding element in B you essentially get the intersection of A and B (i.e., where A and B both equal 1).

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by