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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Image Analyst
Image Analyst el 30 de Mayo de 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 comentarios
Image Analyst
Image Analyst el 30 de Mayo de 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 el 30 de Mayo de 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".

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by