Hi. I have this problem, I run into it all the time and the only way I solve it is with a for loop. I am sure there is a simple solution, but I have tried everything I can think of.
I want to select a subset of values. I have for instance calibration data A for frequencies A and I want to select a subset B of these corresponding to frequecies B.
freqA=50:1:100;
dataA=rand(size(freqA));
freqB=50:5:100;
dataB=zeros(size(B));
for k=1:length(B);
dataB(k)=dataA(freqA==freqB(k));
end
This works. But I would like to find a solution that doesn't require a foor loop.
Many thanks in advance!

 Accepted Answer

dpb
dpb on 21 Feb 2017
Edited: dpb on 21 Feb 2017
dataB=dataA(ismember(freqA,freqB));
If the frequencies are floating-point values, above will often fail owing to FP rounding/precision issues. Use ismembertol if have R2015a or later for robustness.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 21 Feb 2017

Edited:

dpb
on 21 Feb 2017

Community Treasure Hunt

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

Start Hunting!