I have a big matrix and I want to correct it The first column I want to remove those -1 and -2 from my data
for example my data is as follows
0,206470489501953 -1,86300277709961 -2,64120101928711
0,270366668701172 -1,92737579345703 -2,63929367065430
0,382900238037109 -1,87778472900391 -2,54106521606445
0,349044799804687 -1,72615051269531 -2,34174728393555
0,287532806396484 -1,63698196411133 -2,47240066528320
I want to have it as follows
0,206470489501953 0,86300277709961 0,64120101928711
0,270366668701172 0,92737579345703 0,63929367065430
0,382900238037109 0,87778472900391 0,54106521606445
0,349044799804687 0,72615051269531 0,34174728393555
0,287532806396484 0,63698196411133 0,47240066528320
nothing changed , I just removed the minus 1 and minus 2 from my data
Unfortunately, I cannot use abs function since I have also big numbers in my data that i cannot touch like follows;
46,5722084045410 110,708236694336 3,10182571411133
44,4703102111816 108,825206756592 4,81796264648438
42,4933433532715 106,929779052734 6,19792938232422
40,4911041259766 104,907035827637 6,72531127929688
I only need to remove those -1, -2, -3 from my data but not changing the positive values with higher than 1 like above

4 件のコメント

Jos (10584)
Jos (10584) 2014 年 1 月 30 日
The presence of commas suggests that this is a text (character, string) matrix rather than a numerical matrix … Is that the case and is is what you really want?
Niki
Niki 2014 年 1 月 30 日
Not really, this is not a text mining, it is values,
Jos (10584)
Jos (10584) 2014 年 1 月 30 日
Usually values contain decimal dots ...
Niki
Niki 2014 年 1 月 30 日
you are right, however thanks

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

 採用された回答

Jos (10584)
Jos (10584) 2014 年 1 月 30 日
編集済み: Jos (10584) 2014 年 1 月 30 日

0 投票

Another problem needs another solution:
a = [0.1234 -1.9876 -2.0001 22.9999]
b = a % work on a copy
q = fix(b)<0
b(q) = abs(rem(b(q),1))

その他の回答 (3 件)

Mischa Kim
Mischa Kim 2014 年 1 月 30 日
編集済み: Mischa Kim 2014 年 1 月 30 日

1 投票

Use the rem command:
A = [0.1 -2.3]
A =
0.100000000000000 -2.300000000000000
abs(rem(A,1))
ans =
0.100000000000000 0.300000000000000

2 件のコメント

Niki
Niki 2014 年 1 月 30 日
Thanks but I cannot use the abs function, I explain more in the text
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 30 日
Then use
idx=A<=-1
A(idx)=rem(A(idx),1)

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

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 30 日
編集済み: Azzi Abdelmalek 2014 年 1 月 30 日

1 投票

idx=A<=-1
A(idx)=A(idx)-fix(A(idx))

1 件のコメント

Niki
Niki 2014 年 1 月 30 日
Thanks but I cannot use the abs function, I explain more in the above text (question)

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

Jos (10584)
Jos (10584) 2014 年 1 月 30 日

0 投票

For numerical arrays use REM and ABS. An example:
a = [0.1234 -1.9876 -2.0001]
b = abs(rem(a,1))
% [0.1234 0.9876 0.0001] as required

1 件のコメント

Niki
Niki 2014 年 1 月 30 日
Thanks but I cannot use the abs function, I explain more in the text

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

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2014 年 1 月 30 日

コメント済み:

2014 年 1 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by