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

1 回表示 (過去 30 日間)
R7 DR
R7 DR 2015 年 5 月 30 日
コメント済み: Image Analyst 2015 年 5 月 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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by