[問題] 挑掉負值已回收

看板MATLAB作者 (開學好不適應)時間16年前 (2008/10/13 00:20), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
1 1 1 0 -1 -1 -1 -1 -1 -1 0 1 0 1 -1 -1 -1 -1 -1 -1 0 0 1 0 -1 -1 -1 -1 -1 -1 1 1 0 1 -1 -1 -1 -1 -1 -1 1 1 0 1 -1 -1 -1 -1 -1 -1 0 1 1 0 -1 -1 -1 -1 -1 -1 0 0 1 0 -1 -1 -1 -1 -1 -1 0 1 1 0 -1 -1 -1 -1 -1 -1 0 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 0 -1 -1 -1 -1 -1 -1 想請教各位因為我有一行式子在加總每一列ex y=sum(x)---->x是上面的東西 一列一列的加,但是我現在有負號的東西不想加進去不知道可不可以? 因為我這個負號不一定會在最後面有可能會在任何地方?以下是我的程式!想破頭啦 x的範圍是0.5到1 bits=[lengh lengh lengh lengh] lengh=10 vub=1 vlb=0.5 function [gen,lchrom,coarse,nround] = encode1(x,vlb,vub,bits) lchrom = sum(bits); coarse = (vub-vlb)./((2.^bits)-1); [x_row,x_col] = size(x); gen = []; if ~isempty(x), temp = (x-ones(x_row,1)*vlb)./ ... (ones(x_row,1)*coarse) b10 = round(temp); % Since temp and b10 should contain integers 1e-4 is close enough nround = find(b10-temp>1e-4); gen = b10to2(b10,bits); end -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.192.240.157

10/13 00:42, , 1F
help find
10/13 00:42, 1F

10/13 07:48, , 2F
y=sum(x(x>0))
10/13 07:48, 2F
文章代碼(AID): #18yYFY14 (MATLAB)
文章代碼(AID): #18yYFY14 (MATLAB)