MATLAB 板


LINE

※ 引述《sonia6121 (sonia)》之銘言: : 這是我第一次發文發問,如有冒犯錯誤請各位大大們糾正我 : 我是matlab新手剛接觸不久 : 最近在寫一個程式 : 我的目的是要把txt檔裡面的值取出來 : [0111 : 00101 : 11011 : ... : ...共26行] : 每行兩兩相比總共會有325種組合 : 長度相同的直接做xor(ex:00101 )xor=11110然後再做sum取出1+1+1+1+0=4這個值 : 11011 : 假如長度不同就要分別用前段跟後段取xor在相加(ex:0111 )xor的作法(0111)=0101 : 00101 0010 : 做sum=2再和xor(0111)=0010 sum=1 相加=3 : 0101 % data generation M = cell(26, 1); for i = 1:26 M{i, 1} = randi(2, randi(2,1,1)+3, 1)' - 1; end % total combinations combns = nchoosek(1:size(M, 1), 2); % results dfree = zeros(size(combns, 1), 1); % computation for i = 1:size(combns, 1) % temporary variables (可以不用,只是程式易讀性低) a = M{combns(i, 1), 1}; b = M{combns(i, 2), 1}; len_a = length(a); len_b = length(b); % if the lengths are equal if len_a == len_b dfree(i) = sum(xor(a, b)); else % nonequal condition if len_a > len_b dfree(i) = sum(xor(a(1:len_b), b)) + ... sum(xor(a((len_a-len_b+1):end), b)); else dfree(i) = sum(xor(a, b(1:len_a))) + ... sum(xor(a, b((len_b-len_a+1):end))); end end end --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.225.239.88
※ 文章網址: https://webptt.com/m.aspx?n=bbs/MATLAB/M.1432193676.A.5D4.html ※ 編輯: celestialgod (36.225.239.88), 05/21/2015 15:57:59
1F:推 sonia6121: 這位大大真是太強了 !感謝!05/21 17:36
2F:→ sonia6121: 請問txt檔取值的部分用我原本那個可以嗎?我原本那個05/21 17:45
應該可以吧,你讀進去也是cell ※ 編輯: celestialgod (36.225.239.88), 05/21/2015 18:03:00







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Soft_Job站內搜尋

TOP