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

5 vues (au cours des 30 derniers jours)
catarina
catarina le 4 Jan 2012
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

Réponses (1)

Dr. Seis
Dr. Seis le 4 Jan 2012
>> 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 commentaires
Dr. Seis
Dr. Seis le 5 Jan 2012
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 le 5 Jan 2012
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).

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by