Notimplemented GE function

Hi,
I am trying to sum alle positive value's in a vector.
Im trying this by;
A=([1;1;-1;-1])
For i=1:4
if A(i,1)>=0
sum(A(i,1))
end
end
But it doesnt work, GE is not implemented, i have a student version sow..
Anyone has an alternitive?
I will have a vector with appr. 8000 rows with data, is there an easy way to analyse this data?

回答 (6 件)

Andrew Newell
Andrew Newell 2011 年 2 月 17 日

1 投票

sum(A(A>=0))
EDIT: better still,
sum(A(A>0)
Walter Roberson
Walter Roberson 2011 年 2 月 17 日

1 投票

I suspect your actual code has
A = {[1;1;-1;-1]};
or
A = {1;1;-1;-1};
If so then A is a cell array, and A(i,1) is a cell array, and > is not defined for cell arrays. To access the content of A(i,1) in such a case, you would use A{i,1}
Andrew Newell
Andrew Newell 2011 年 2 月 17 日

0 投票

I should add that your code doesn't work because it has some errors in it, not because GE is not implemented. A version that is similar to yours but works is
A=([1;1;-1;-1]);
AposSum = 0;
for i=1:4
if A(i,1)>=0
AposSum = AposSum + A(i,1);
end
end
AposSum
Frank
Frank 2011 年 2 月 24 日

0 投票

How do i know if it is a cell/array/matrix or something?
It has in the workspace a Cube in front of it, re.. Could it be called " Tensile Data"?
I think i am doing something wrong with writing my data... I tried a lot..
Isnt it possible to export it to a Txt file and then read it in again?
Thanks in advance!

2 件のコメント

Andrew Newell
Andrew Newell 2011 年 2 月 24 日
Look at the Value column, to the right of Name. It should say something like <8000x1 cell> or [8000x1 double]. If it's the latter, you should be able to use my method.
Andrew Newell
Andrew Newell 2011 年 2 月 24 日
If you're still not sure, type "whos A" and paste the answer in your question.

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

Andrew Newell
Andrew Newell 2011 年 2 月 24 日

0 投票

If Walter is right and it's a cell array, you could do this:
ipos = [A{:}]>0;
if any(ipos)
Asum = sum(A{ipos});
else
Asum = 0;
end
That funny looking first line extracts the values of A using A{:} and then puts it in a double array using [].
Frank
Frank 2011 年 2 月 24 日

0 投票

I solved it!
B=double(A) makes the matrix numeric or something like that, now i can do everything i want with it!
Anyways, thank u all for the help!

3 件のコメント

Andrew Newell
Andrew Newell 2011 年 2 月 24 日
So what type was it before?
Walter Roberson
Walter Roberson 2011 年 2 月 24 日
If double() worked to make it numeric, then it must have been symbolic.
Andrew Newell
Andrew Newell 2011 年 2 月 24 日
That would also explain the problem with GE.

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

カテゴリ

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

質問済み:

2011 年 2 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by