Extract a range of frequencies and power from X-Y vector/array

Hello,
I hope you are in good health.
I am trying to select a range of frequencies and their corresponding power from the given data set.
load phaseNoise.mat
plot(fnew,pnew)
xRange_new = fnew(fnew == 10e+009 | fnew <= 30e+009);
x_index = find (fnew == xRange_new);
Arrays have incompatible sizes for this operation.
yRange_new = pnew(x_index);
plot(xRange_new, yRange_new)
However, I get an error when I try to find the indexes of the specific frequencies saying that 'Arrays have incompatibel sizes for this operation.'. I know that the array sizes are different but I want to know how can I extract the x and y values simultaneously. I can use the zoom feature to only display the part I want but that's not what I want.
(If finding the indexes of the x values are not necessary then guide me on achieving the desired results so...)
Basically, I want to only select the frequencies from 10GHz to 30GHz and their corresponding Y-values and discard the rest of the values so I can display the graph from 10GHz to 30GHz and perform further analysis on the given range only.
Any help will be appreciated.
BR.

 Accepted Answer

hello
some minor bugs , see comments
this is what you wanted :
load phaseNoise.mat
plot(fnew,pnew)
x_index = (fnew >= 10e+009 & fnew <= 30e+009); % & , not | !!; also, logical indexing suffices , no need to use "find"
xRange_new = fnew(x_index);
yRange_new = pnew(x_index);
plot(xRange_new, yRange_new)

4 Comments

Thank you for the corrections.
Yes, this is what I wanted. However, the x_index is returning a logical array with 0s and 1s only. Therefore, can you simplify how the xRange_new = fnew(x_index) and yRange_new = pnew(x_index) are extracting the values from the given arrays because it is either fnew(0) or fnew(1).
Thanks once again...
hello
I am not sure to understand what you mean by "simplify" in your sentence :
Therefore, can you simplify how the xRange_new = fnew(x_index) and yRange_new = pnew(x_index) are extracting the values from the given arrays because it is either fnew(0) or fnew(1).
using logical index means that xRange_new will contain only the "valid" fnew data (valid here means where the logical index is non zero)
So the xRange_new will read the indexes from x_index and pick the corresponding value from fnew (for valid indexes only).
Like if the value of index 1001 in x_index is 1, so the xRange_new = fnew(x_index) will display the value at position 1001 in the fnew array, right?
That's all...
Thank you. I understand it now.
BR.
yes , you got it !
all the best
MN

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022a

Asked:

on 27 Sep 2022

Commented:

on 29 Sep 2022

Community Treasure Hunt

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

Start Hunting!