How to write comments defining the elements in a 2d array?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
Dr. Seis
il 4 Gen 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 Commenti
Dr. Seis
il 5 Gen 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
il 5 Gen 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).
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!