Intersection of two matrices

3 ビュー (過去 30 日間)
Shaden Baradie
Shaden Baradie 2017 年 11 月 3 日
回答済み: Walter Roberson 2017 年 11 月 4 日
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??

回答 (2 件)

Steven Lord
Steven Lord 2017 年 11 月 3 日
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 件のコメント
Shaden Baradie
Shaden Baradie 2017 年 11 月 4 日
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.

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


Walter Roberson
Walter Roberson 2017 年 11 月 4 日
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)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by