How to pull similar data from different sized matrices?

1 view (last 30 days)
I have matrices that are a lot of rows and 2 columns. The first column is a linspace from 1 to a lot and the second column is data for a specific parameter. These matrices change in row size for each new file I load. I am plotting each parameter and plot brushing and saving(ans) a specific time frame I will use for further analysis. I would like to apply this time frame to each parameter.
Previously I would find the max and min values of my linspace that I brushed and assign that range to each parameter.
brushed_data = ans(:,1)
size2 = size(brushed_data,1)
Start = min(brushed_data)
Stop = Start+size2-1
My new parameters would then be assigned like so:
IAMHS2 = IAMHS(Start:Stop,1);
My new parameters aren't all the same size though. When I read the file in I have to remove rows for some parameters because they are empty (NaN). For example two parameters will look something like
set1 = [1 data; 2 data; 3 data; 4 data; 5 data; 6 data; 7 data; 8 data; 9 data; 10 data]
set2 = [2 data; 4 data; 6 data; 9 data; 10 data]
I would like to be able to recognize the min and max linspace values of the brushed data.
brushed_data = ans
start = min(brushed_data(:,1))
stop = max(brushed_data(:,1))
Then pull all values greater then or equal to the start values and less than or equal to the stop values. (This is my problem)
>=Start and <=Stop
So for instance if I brushed data in set1 for values 3-9 I would like to be able to reassign set2 for the same range. So it would only contain
[4 data; 6 data: 9 data]
Similarly if I brushed data in set2 for values 4-9 I would reassign set1 for the same range.
[4 data; 5 data; 6 data; 7 data; 8 data; 9 data]

Accepted Answer

dpb
dpb on 14 Sep 2015
Not sure where the problem lies, exactly, or the actual question but---
set1=set1(iswithin(set1(:,1),3,9),:);
will turn set1 into those elements within the range 3,9 given in the first column.
iswithin is "syntactical sugar" but is a utility function I find worth keeping around as it simplifies the syntax of the comparisons otherwise needed as is, I think, more legible and certainly easier to use directly in indexing expressions as the above.
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!