Intersection of two matrices

3 vues (au cours des 30 derniers jours)
Shaden Baradie
Shaden Baradie le 3 Nov 2017
Hello.. I have an attenuation data of 2678400 values and I am trying to determine a fading level of 5dB and observe the intersection points where the attenuation data crosses the determined level in order to study fading durations.. I created a matrix with the same length with all of its values equal to 5, but the problem is that when I compare the two matrices to each other I get an empty matrix as a result.. even when using the intersect function the same result came out.. any suggestions to solve this problem please??

Réponses (2)

Steven Lord
Steven Lord le 3 Nov 2017
Remember that == tests for exact, down-to-the-last-bit equality. The == operator is neither horseshoes nor hand grenades, so "close enough" doesn't count. While elements in your attenuation vector may look like they contain the value 5, they may not be exactly 5.
format longg
x = 1
y = x+eps(x) % this _looks_ like it has the same value as x
x == y % false because y doesn't have exactly the same value as x
If you want to find some number of the first or last elements in your vector that satisfy some criterion, use the find function.
z = 1:100;
firstThreeElementsGreaterThan5 = find(z > 5, 3, 'first')
  1 commentaire
Shaden Baradie
Shaden Baradie le 4 Nov 2017
Thank you, that helped finding the values, but how can I plot the attenuation values of (2678400*1) with the values greater than 5 (46619*1) since the find command is creating the answer as a new matrix.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 4 Nov 2017
mask = (Attenuationvalues(:) > 5).'; %row vector
starts = strfind([false, mask], [0 1]);
stops = strfind([mask, false], [1 0]);
Now each starts(K) is the beginning of a stretch in which the value is above 5 and stops(K) is the end of the corresponding stretch. Values that are exactly 5 would not be included because of the use of > instead of >= .
... but have you considered just
temp = AttenuationValues;
temp(temp <= 5) = nan;
plot(appropriate_x, temp)

Catégories

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by