Re: [問題]很奇怪的 floor已回收
我也有類似的經驗
tx=-6:0.1:6;
我想讓他對映到 ix=1:121;
也就是 -6.0 -5.9 -5.8 ...... 0.2 5.8 5.9 6.0
↓
對映到 1 2 3 ...... 63 119 120 121
我原先很直覺用 ix=fix(tx*10+61);
結果程式一直錯 搞到我快瘋掉
只好從頭到尾檢查一遍
才發現居然是我覺得最不會有問題的地方有錯
當tx=0.2時 算出來的ix是62
0.2*10+61應該要等於63啊
我也不知道為什麼會這樣
於是我把我的參考書洪維恩那本拿來翻
把有關捨位的函數全用上
fix, floor, ceil, round
寫了一個m檔案來檢查到底哪個才是我要用的函數
=============================================
clear
tx=-6:0.1:6;
ix=1:121; %用來對照用的
ix1=fix(tx*10+61)-ix;
ix2=floor(tx*10+61)-ix;
ix3=ceil(tx*10+61)-ix;
ix4=round(tx*10+61)-ix;
%如果不是一條水平線就是錯的
subplot(2,2,1); plot(tx,ix1,'-'), title('fix')
subplot(2,2,2); plot(tx,ix2,'-'), title('floor')
subplot(2,2,3); plot(tx,ix3,'-'), title('ceil')
subplot(2,2,4); plot(tx,ix4,'-'), title('round')
=============================================
發現round才是我要的
程式也才邁向下一步
--
-好管弦事-
A place about cello and music....
http://fnt72.blogspot.com/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.67.47
※ 編輯: kobenein 來自: 140.123.67.47 (03/09 20:49)
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章