matlab循环怎么写
1. matlab里多个for循环的嵌套循环语句怎么写
不知道参数具体数值无法运行,这里给你指出编程错误。
1
2
3
4
5
6
7
8
9
10
if s1>s2
for i=150:15:0;%应修改为i=150:-15:0
new1=AFFT(im1,i);
s10=AS(new1);
if abs(s10-s2)subplot(1,2,1),imshow(new1,[])
subplot(1,2,2),imshow(im2,[])
%这里你是否只需画一幅图?根据你的表达退出所有循环这里要加个break
end
end%最后仍缺个end
修改程序如下:
1
2
3
4
5
6
7
8
9
10
11
if s1>s2
for i=150:-15:0
new1=AFFT(im1,i);
s10=AS(new1);
if abs(s10-s2)subplot(1,2,1),imshow(new1,[])
subplot(1,2,2),imshow(im2,[])
break
end
end
end
2. 用MATLAB怎么写这几道题1.分别用for和while循环结构编写程序,求出
第一题:function y=fuc2(i) y=0;if i==0 y=1; %无意义的输出else for j=1:i y=y+2^j; endend在command windows中输入>> fuc2(63)ans = 1.8447e+019第二题:j=0;for i=2000:3000if (mod(i,400)== 0)||((mod(i,4)==0)&&(mod(i,100)~= 0)) j=j+1;endendx=zeros(1,j);j=1;for i=2000:3000if (mod(i,400)== 0)||((mod(i,4)==0)&&(mod(i,100)~= 0)) x(1,j)=i; j=j+1;endend运行后,j的数值即为闰年的个数,x数组中的数即为各个闰年的年份第三题:syms asimplify(cos(4*a)-4*cos(2*a)+3)运行后,就可得到ans =8*sin(a)^4第四题:for i=1:0.01:10subplot(2,2,1); plot(i,sin(2*i)); hold ontitle('sin2x')subplot(2,2,2); plot(i,tan(i));ylim([-10,10]) ;hold ontitle('tanx')subplot(2,2,3); plot(i,log(i)); hold ontitle('lnx')subplot(2,2,4); plot(i,10^i); hold ontitle('10x')end运行后就可以得到图片如下:注意:以上4个程序最好都以M文件的形式写比较好.。
3. matlab中for循环怎么写
在classpath(例如web-inf\classes)中放一个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
4. matlab中如何写循环
disp('Please enter the value:\n');
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
5. matlab中两个变量的for循环怎么写
你大概是想要这个样子吧
y=zeros(10,10);
for i=1:10
for x=1:10
y(i,x)=3*x;
end
end
y=
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
matlabfor循环怎么写
1. matlab中for循环怎么写
在classpath(例如web-inf\classes)中放一个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
2. matlab中两个变量的for循环怎么写
你大概是想要这个样子吧
y=zeros(10,10);
for i=1:10
for x=1:10
y(i,x)=3*x;
end
end
y=
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3 6 9 12 15 18 21 24 27 30
3. matlab怎样用for循环
这道题不需要for循环呀
x=[566.66475,566.719625,566.7735,566.816125,566.862125,566.908375,566.94675,566.98425,567.02175,567.056875,567.1045,567.15175,567.085,567.0995313];
kx=239.20943546./((239.20943546*x-135480.34239240469097801138675924).^2+1).^1.5
运行结果:
kx =
1.0e-03 *
Columns 1 through 7
0.662186381707795 0.398656447781425 0.260228235798709 0.192944098695949 0.144007475910162 0.110161864502044 0.089701671923601
Columns 8 through 14
0.074325291610649 0.062271686339828 0.053235759535329 0.043573800786434 0.036167178263329 0.047221464414296 0.044466533890759
4. MATLAB中的for循环怎么用
Matlab中matlab中for 循环的原理和应用for 循环是用在须重复执行且执行次数有一定的算式,它的结构如下:for index = arraycommand Aend如果我们要计算一缆车离铁塔的速度 (v),它的速度计算方式与且铁塔的距离 (d)有关,假设以 10 公尺为判断值,则速度计算分为二个算式:假设有一个阵列 d 为缆车到铁塔的距离,则以下的for 循环可计算速对应的速度 >> for k = 1:length(d)if d(k) <= 10velocity = 0.425 + 0.00175*d(k)^2;elsevelocity = 0.625 + 0.12*d - 0.00025*d(k)^2;endfprintf('d= %f velocity= %f\n',d(k),velocity)end另外几个例子>> for n=1:10x(n)=sin(n*pi/10);end>> disp(x)>> for n=1:5for m=5:-1:1A(n,m)=n^2+m^2;enddisp(n)end>> disp(A)但是如果可以用阵列或是矩阵运算来取代以for 循环计算,就应采用前者因为计算速度快多了。
上述的例子 可改为>> n=1:10;>> x=sin(n*pi/10);使用 for 循环的规则如下:上述的 for 循环中的指标 (index) 须为是一变数。如果 array 代表阵列是空无一物,则循环不会被执行,例如 k=1:0。
如果 array 代表阵列是一纯量,则循环会被执行一次,例如 k=1:1。如果 array 代表阵列是一向量,则循环会被依序的执行,例如 k=1:b, b=[1 3 5]。
如果 array 代表阵列是一矩阵,则循环会被逐行依序的执行,例如 k=1:B, B=[1 2; 3 4]。for 完整的语法为: for k = first:increment:last,其中的 first, increment, last分别为初始值,增量,终止值。
而循环被执行的次数由以下的算式决定: 1. 2. 3. 4. 5. 6.floor((last-first)/increment)+1如果计算得到的值为负,则循环不被执行。
5. matlab里多个for循环的嵌套循环语句怎么写
不知道参数具体数值无法运行,这里给你指出编程错误。
1
2
3
4
5
6
7
8
9
10
if s1>s2
for i=150:15:0;%应修改为i=150:-15:0
new1=AFFT(im1,i);
s10=AS(new1);
if abs(s10-s2)subplot(1,2,1),imshow(new1,[])
subplot(1,2,2),imshow(im2,[])
%这里你是否只需画一幅图?根据你的表达退出所有循环这里要加个break
end
end%最后仍缺个end
修改程序如下:
1
2
3
4
5
6
7
8
9
10
11
if s1>s2
for i=150:-15:0
new1=AFFT(im1,i);
s10=AS(new1);
if abs(s10-s2)subplot(1,2,1),imshow(new1,[])
subplot(1,2,2),imshow(im2,[])
break
end
end
end
6. matlab中for循环
程序实现的功能:
矩阵a如下
12 13 14
15 16 17
18 19 20
21 22 23
将矩阵a的每一行相加求和,得到一个列向量经过转置成行向量
clear;clc
s=0; %赋给s初值0
a=[12,13,14;15,16,17;18,19,20;21,22,23]; %4*3矩阵a
for k=a %k取a的每一列(不是每一个值或每一行),进行循环
s=s+k %每一列对应的元素相加,迭代求和
end
disp(s') %转置,将列向量转化为行向量
运行结果如下:
s =
12
15
18
21
s =
25
31
37
43
s =
39
48
57
66
39 48 57 66
你看一下结果就知道了。
matlab怎么写for循环语句
1. matlab里多个for循环的嵌套循环语句怎么写
不知道参数具体数值无法运行,这里给你指出编程错误。
1
2
3
4
5
6
7
8
9
10
if s1>s2
for i=150:15:0;%应修改为i=150:-15:0
new1=AFFT(im1,i);
s10=AS(new1);
if abs(s10-s2)subplot(1,2,1),imshow(new1,[])
subplot(1,2,2),imshow(im2,[])
%这里你是否只需画一幅图?根据你的表达退出所有循环这里要加个break
end
end%最后仍缺个end
修改程序如下:
1
2
3
4
5
6
7
8
9
10
11
if s1>s2
for i=150:-15:0
new1=AFFT(im1,i);
s10=AS(new1);
if abs(s10-s2)subplot(1,2,1),imshow(new1,[])
subplot(1,2,2),imshow(im2,[])
break
end
end
end
2. matlab中for循环怎么写
在classpath(例如web-inf\classes)中放一个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怎样用for循环
这道题不需要for循环呀
x=[566.66475,566.719625,566.7735,566.816125,566.862125,566.908375,566.94675,566.98425,567.02175,567.056875,567.1045,567.15175,567.085,567.0995313];
kx=239.20943546./((239.20943546*x-135480.34239240469097801138675924).^2+1).^1.5
运行结果:
kx =
1.0e-03 *
Columns 1 through 7
0.662186381707795 0.398656447781425 0.260228235798709 0.192944098695949 0.144007475910162 0.110161864502044 0.089701671923601
Columns 8 through 14
0.074325291610649 0.062271686339828 0.053235759535329 0.043573800786434 0.036167178263329 0.047221464414296 0.044466533890759
4. Matlab for循环语句
示例1:
x =
0.5878 0.9511 0.9511 0.5878 0.0000 -0.5878 -0.9511 -0.9511 -0.5878 -0.0000
示例2:
array =
6 3 7 8 5 1 2 4 9 10
x1 =
0.5878 0.9511 0.9511 0.5878 0.0000 -0.5878 -0.9511 -0.9511 -0.5878 -0.0000
换一个matlab运行就可以
5. matlab 如何使用循环语句
原发布者:jinziyatoo
循环结构1.for语句for语句的格式为:for循环变量=表达式1:表达式2:表达式3循环体语句end其中表达式1的值为循环变量的初值,表达式2的值为步长,表达式3的值为循环变量的终值。步长为1时,表达式2可以省略。for语句更一般的格式为:for循环变量=矩阵表达式循环体语句end执行过程是依次将矩阵的各列元素赋给循环变量,然后执行循环体语句,直至各列元素处理完毕。2.while语句while语句的一般格式为:while(条件)循环体语句end其执行过程为:若条件成立,则执行循环体语句,执行后再判断条件是否成立,如果不成立则跳出循环。3.break语句和continue语句与循环结构相关的语句还有break语句和continue语句。它们一般与if语句配合使用。break语句用于终止循环的执行。当在循环体内执行到该语句时,程序将跳出循环,继续执行循环语句的下一语句。continue语句控制跳过循环体中的某些语句。当在循环体内执行到该语句时,程序将跳过循环体中所有剩下的语句,继续下一次循环。求[100,200]之间第一个能被21整除的整数forn=100:200ifrem(n,21)~=0continueendbreakendn4.循环的嵌套如果一个循环结构的循环体又包括一个循环结构,就称为循环的嵌套,或称为多重循环结构。例3-13若一个数等于它的各个真因子之和,则称该数为完数,如6=1+2+3,所以6是完数。求[1,500]之间的全部完数。form=1:500s=0;fork=1:m/2ifr
6. matlab中的for语句怎样编多层循环的程序
很高兴为您解答这个问题,for语句编多层循环,只需要简单嵌套就好了。示例如下:
C=zeros(5,5); %C是全0矩阵,用来保存矩阵A*B的成绩,A为5*3矩阵,B为3*5矩阵
%下面的元素为C的每一个元素求值
for i=1:5
for j=1:5
for k=1:3
%这里是你要实现的关于i,j,k三个变量的语句。
C(i,j)=A(i,k)*B(k,j); %这是一个关于矩阵乘法的循环语句。
end
end
end
希望可以帮助你,祝学习进步!
转载请注明出处育才学习网 » matlab里面for循环怎么写
育才学习网