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

조회 수: 1 (최근 30일)
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

채택된 답변

Image Analyst
Image Analyst 2015년 5월 30일
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
Image Analyst
Image Analyst 2015년 5월 30일
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 2015년 5월 30일
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".

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by