Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

scilab for迴圈

178 views
Skip to first unread message

j...@hoyan-optics.com

unread,
Jun 30, 2013, 10:52:24 PM6/30/13
to ade-s...@googlegroups.com
大家好

我一直有個問題不知道該怎麼處理
在for迴圈裡

d1=0.0015
for i=0 :d1:10

就我所知道增量的d1好像最小單位是1
那以上的情形我該怎麼處理呢??

請大家給我指導 謝謝


j...@hoyan-optics.com

unread,
Jul 1, 2013, 12:29:33 AM7/1/13
to ade-s...@googlegroups.com
問題修正一下
應該說是
我想要輸出資料
0.001
0.002
0.003
0.004
0.005
0.006
0.007
0.008
0.009
0.01
使用for
d1=0.001
x=zeros(1,10)
for i=0 :d1:10
x(i)=i
end

我知道好像是x(i)這裡出問題
請問一下我該如何改呢??


j...@hoyan-optics.com於 2013年7月1日星期一UTC+8上午10時52分24秒寫道:

Yung-Jang Lee

unread,
Jul 1, 2013, 8:59:40 AM7/1/13
to ade-scilab
這樣 :
-------------------------------
d1
=0.001 for i=1:11 x(i)=(i-1)*d1 // x(i) 內的 i 必須  >=1 end
--------------------------


--
您已訂閱「Google 網上論壇」的「中文 Scilab 教育論壇」群組,因此我們特別傳送這封郵件通知您。
如要取消訂閱這個群組並停止接收來自這個群組的郵件,請傳送電子郵件到 ade-scilab+...@googlegroups.com
如要在此群組張貼留言,請傳送電子郵件至 ade-s...@googlegroups.com
請前往以下網址造訪這個群組:http://groups.google.com/group/ade-scilab。
如需更多選項,請前往:https://groups.google.com/groups/opt_out。
 
 

j...@hoyan-optics.com

unread,
Jul 1, 2013, 9:28:02 PM7/1/13
to ade-s...@googlegroups.com
Hi YungLee

感謝您的回覆
我想是我的問法有問題
我了解到你在解答中有提到x(i)裡的i必須為>=1的數值
因此您用的解法只適用在這個特殊的舉例中
可否再請您幫忙解答一下
我把我碰到的問題附加在檔案裡
clear all;
[filename, pathname] = uigetfile('*.prf','Select input data file (*.prf)');
filename1=[pathname,filename];

[filename, pathname] = uiputfile('*.txt','Save output data file (*.txt)');
filename2=[pathname,filename];
%%%%CZ M 2.995200e+004 MM 8.000000e-007 L
[t1, t2, t3, t4, t5, t6]=textread(filename1,'%s %s %s %s %s %s','headerlines',3);
we=t5(1,1)
wt=str2double(we);
%%%%SPACING CX 1.250000e-004
[u1, u2, u3]=textread(filename1,'%s %s %s','headerlines',6);
yi=u3(1,1)
gy=str2double(yi);

[a1]=textread(filename1,'%s','headerlines',10);
BB=a1;
qw=size(BB)-2;
jk=qw(1,1)
m=BB(1:qw,1);

V1=str2double(m);

x = zeros(jk,2); % 變數 x 是一個 1×6 大小的零矩陣  
for i = 1:gy:jk
x(i)=i;  
end

gy這個變數是一句我所讀進的*.prf檔案所去決定
因此您之前所說的解法不適合我用
我想要達到的目的是
一個矩陣排列
依附加的prf檔案來說則是如下

0.000000
0.000125
0.000250
0.000375
0.000500
0.000625
0.000750
0.000875
0.001000.......

不知您是否有什麼想法覺得可行

以上  謝謝






j...@hoyan-optics.com於 2013年7月1日星期一UTC+8上午10時52分24秒寫道:
matrix_folwtest.m
S0025 P1 R2-X-C1.PRF

李建緯

unread,
Jul 1, 2013, 9:33:33 PM7/1/13
to ade-s...@googlegroups.com

gy這個變數是依據我所讀進的*.prf檔案所去決定

因此您之前所說的解法不適合我用

我想要達到的目的是

一個矩陣排列

依附加的prf檔案來說則是如下

不知您是有什麼想法覺得可行

以上  謝謝

 

0.000000

0.000125

0.000250

0.000375

0.000500

0.000625

0.000750

0.000875

0.001000.......

                                                

 

我有同步發表到中文 Scilab 教育論壇

但怕您誤解因此直接發mail跟您請教

 

以上  謝謝

S0025 P1 R2-X-C1.rar

Yung-Jang Lee

unread,
Jul 2, 2013, 10:21:04 AM7/2/13
to ade-scilab
你送來的是 Matlab code, 我無法幫你改成 Scilab



gy=str2double(yi);  //gy 為實數

......

for i = 1:gy:jk // i=1,1+gy,1+2*gy,.....

        x(i)=i;    // 第二筆會出錯( i=1+gy 不是整數)

end


Reply all
Reply to author
Forward
0 new messages