フィルターのクリア

How to concatinate two intervals in a vector?

3 ビュー (過去 30 日間)
sH
sH 2015 年 6 月 12 日
編集済み: Image Analyst 2015 年 6 月 13 日
Hello How to construct this vector? b ∈[−3e10, −10e10]∪[10e10,30e10]
  2 件のコメント
James Tursa
James Tursa 2015 年 6 月 12 日
Concatenate in what way? Have a 4 element output? A 2 element output spanning both? Or what? What would be the desired output for your example?
sH
sH 2015 年 6 月 12 日
編集済み: Image Analyst 2015 年 6 月 12 日
I have written this code and I want this output
[3e10 : 1e10 : 10e10, 10e10 : 1e10 : 30e10]
I want to know is there a better code?

サインインしてコメントする。

回答 (2 件)

Star Strider
Star Strider 2015 年 6 月 12 日
編集済み: Star Strider 2015 年 6 月 12 日
Not certain what you want, but MATLAB has a union operator. Note that it sorts the output:
B = union([-3e10, -10e10],[10e10,30e10])
produces:
B =
-100.0000e+009 -30.0000e+009 100.0000e+009 300.0000e+009
EDIT With your new vectors, use union but with a slightly different syntax:
B = union(-30e10 : 1e10 : -10e10, 10e10 : 1e10 : 30e10);
I believe there is an error in your code. The first element of the first vector should be -30e10, otherwise the first element is greater than the last element, and the colon (:) operator will evaluate it as empty. (I corrected it in my edited code.)

Image Analyst
Image Analyst 2015 年 6 月 12 日
編集済み: Image Analyst 2015 年 6 月 13 日

You cannot go from -3 to -10 in steps of +1. Did you mean

v = [-3e10 : -1e10 : -10e10, 10e10 : 1e10 : 30e10]

If so, that's a perfectly fine way of constructing that vector.

If there is some overlap in the ranges, then perhaps you might want to run it through unique():

v = unique([-3e10 : -1e10 : -10e10, -10e10 : 1e10 : 30e10])

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by