How to load the specific data to a new variable as per the required condition?

1 view (last 30 days)
I have 4 data sets for example..
a=[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
b=[ 1 2 3 4 5 6 7 8 9]
c=[11 12 13 14 15 16 17 18 19]
d=[21 22 23 24 25 26 27 28 29]
In this case how to load the data from the specific variable 'c' if 'a'>0.2 && <0.7.
In this example the result is e=[13 14 15 16]
Thanks

Accepted Answer

Image Analyst
Image Analyst on 30 May 2015
Try this:
a=[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
b=[ 1 2 3 4 5 6 7 8 9]
c=[11 12 13 14 15 16 17 18 19]
d=[21 22 23 24 25 26 27 28 29]
columnsToExtract = a>0.2 & a<0.7
e = c(columnsToExtract) % [13 14 15 16]
  2 Comments
Image Analyst
Image Analyst on 30 May 2015
R7 DR's "Answer" moved here:
Thanks its working fine.
If I want to extract the data from two varaibles at the same time, then how to modify the code?
For example from 'd' to 'f' %%[23 24 25 26].
from 'C' to 'e' %%[13 14 15 16].
Thanks
Image Analyst
Image Analyst on 30 May 2015
It's the same concept. Assuming you're still basing what columns to extract on "a", then you just do:
% Extract from "d" and put into "f"
f = d(columnsToExtract)
% Now extract from some new capital C vector,
% which will overwrite the "e" we got from lower case "c" vector
e = C(columnsToExtract)
If this answers your question, can you mark it as "Accepted".

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!