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

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Image Analyst
Image Analyst le 30 Mai 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 commentaires
Image Analyst
Image Analyst le 30 Mai 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 le 30 Mai 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".

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by