綜合知識

當前位置 /首頁/綜合知識 > /列表

matlab怎麼寫循環

1. matlab中如何寫循環

disp('Please enter the value:n');

matlab怎麼寫循環

j=1;

b=input('Enter the value of b:n');

while b(j)~='|'

j=j+1;

b(j)=input('Enter the value of b:n'); % 輸入數據當輸入‘|’時結束輸入

end

n=length(b(1:end-1));

b=b(1:end-1);

a=zeros(n,1); %建立輸出矩陣

%使用矩陣思維 小數據和c語言思維沒什麼差別但是大量數據時會有明顯差別

k=find(b>=90);

a(k)=5;

k1=find((b>=80).*(b<90)); %注這是數組點乘 .*

a(k1)=4;

k2=find((b>=70).*(b<80));

a(k2)=3.5;

k3=find((b>=60).*(b<70));

a(k3)=3;

k4=find(b<60);

a(k4)=0;

disp(a)

% 下面用的是c語言的思維

% for i=1:n

% if (b(i)>=90) % 幾個分級判斷,可以根據你的具體規定修改

% a(i)=5;

% elseif (b(i)<90 && b(i)>=80)

% a(i)=4;

% elseif (b(i)<80 && b(i)>=70)

% a(i)=3.5;

% elseif (b(i)<70 && b(i)>=60)

% a(i)=3.0;

% else

% a(i)=0;

% end

% end

2. matlab中for循環怎麼寫

在classpath(例如web-infclasses)中放一個log4j.properties就可以了。

例子如(這是是打在stdout中的):

log4j.rootLogger=INFO, CONSOLE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender

log4j.appender.CONSOLE.Target=System.out

log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout

log4j.appender.CONSOLE.layout.ConversionPattern=%d %-5p - [%t] %c{2} - %m%n

3. 怎樣用MATLAB編一個循環語句

clear;clc;clf;

t=0:pi/20:2*pi;

R=10;r=2;

x=R*cos(t);

y=R*sin(t);

m=0;

kk=2*pi/6;

for k=0:kk:2*pi-kk

xi(m+1)=R*cos(k);

yi(m+1)=R*sin(k);

xx(:,m+1)=xi(m+1)+r*cos(t);

yy(:,m+1)=yi(m+1)+r*sin(t);

hold on

line([0 xi(m+1)],[0 yi(m+1)])

m=m+1;

end

plot(x,y,'r',xx,yy)

axis equal

再重複,就編一個子程序,不斷調用。

TAG標籤:matlab #