making an array 'skip' some numbers

Hi everyone,
I am trying to make an array that looks for example like this:
x= -4 -3 -2 2 3 4
So in this example I skipped the -1 the 0 and the 1. How can I make somethink like this in matlab?
Thanks in advance

 採用された回答

Iain
Iain 2014 年 2 月 19 日

2 投票

left_x = -4:-2;
right_x = 2:4;
x = [left_x right_x];
You could do also something like:
x = [-180:10:-110 -105:5:-45 -44:44 45:5:105 110:180];

1 件のコメント

Doubutsu
Doubutsu 2014 年 2 月 19 日
Oh, it was that simple all this time! Thanks a lot. I really wonder why I did not just try that.

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

その他の回答 (3 件)

per isakson
per isakson 2014 年 2 月 19 日

0 投票

Try
x =( -4:1:4);
x(abs(x)<=1)=[];

1 件のコメント

Doubutsu
Doubutsu 2014 年 2 月 19 日
wow it does exactly what I wanted. Thanks.
Could you also explain how it works?

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

Doubutsu
Doubutsu 2014 年 2 月 19 日

0 投票

Having giving it some more thought I would like to be capable of doing something more like making two array's and then put them together. Like having one array that goes like -5 -4.5 -4 -3.5 and one being 3.2 3.4 3.6 3.8 and then put them together got make one array looking like -5 -4.5 -4 -3.5 3.2 3.4 3.6 3.8
So I want to be able to make those two array seperate from each other.
Sorry for the confusion
Jos (10584)
Jos (10584) 2014 年 2 月 19 日

0 投票

A = -5:0.5:-3.5
B = 3.2:0.2:3.8
C = [A B]
C = sort(C) % if A and B overlap?
help colon

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2014 年 2 月 19 日

回答済み:

2014 年 2 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by