求一个简单的matlab程序代码,只要符合要求即可 matlab / \ 符号是什么意思
matlab\u4e2d{:}\u662f\u4ec0\u4e48\u610f\u601d\u5982\u679c\u4f60\u539f\u6765\u5b9a\u4e49\u7684nump\u4e3a\u5143\u80de\u6570\u7ec4\uff0c\u5219nump = nump{:}\u4e3a\u8f6c\u6362\u4e3a\u77e9\u9635\u3002
\u4f8b\u5982\uff1a
>> A = {[1,4,3;0,5,8;7,2,9]}
A =
[3x3 double]
>> A=A{:}
A =
1 4 3
0 5 8
7 2 9
\u6ce8\u610f\u8fd9\u79cd\u65b9\u5f0f\u4ec5\u80fd\u53d6\u51fa\u5143\u80de\u6570\u636e\u7684\u7b2c\u4e00\u4e2a\u5143\u80de
\u4f8b\u5982\uff1a
>> A = {[1,4;0,5],[1 2;1 0]}
A =
[2x2 double] [2x2 double]
>> A = A{:}
A =
1 4
0 5
10 MATLAB\u7b26\u53f7\u8fd0\u7b97
n=length(x);
for i=1:n;
if x(i)>2
y(i)=fun1(x(i));
else
y(i)=fun2(x(i));
end
end
y
这是主程序。下面两个分别保存成M文件
function y = fun1(x)
y=x*x+1;
end
function y = fun2(x)
y=x-1;
end
1、题目:
把1-10的整数,先判断是否为偶数,并计算它们的和,最后做一下验证
2、程序:
clc;clear;
sum0=0;
for i=1:10 %循环
if(mod(i,2)==0)%分支
sum0=sum0+i;
end
end
%检测
test_data=[2:2:10];%顺序
test=sum(test_data);
[sum0 test]
3、运行结果:
ans =
30 30
绛旓細minmax.m function [A,B,C,m,n]=minmax(a,b,c,minmax)杈撳叆涓嶅悎娉曞氨涓嶉獙璇佷簡 A,B,C鍒嗗埆杩斿洖amax锛宐x鏈澶у(鎴栨渶灏忓)锛屼笌bx鍚岃鐨刢,minmax=1姹鏈灏忥紝minmax=2姹傛渶澶 m杩斿洖amax涓暟锛宯杩斿洖bmax涓暟 鍚屾ゼ涓婇鐩‘瀹炲緢闅剧悊瑙o紝甯屾湜鍐欐竻妤氱偣锛屽洖绛旂殑浜轰細澶氱偣 鐢matlab鍐欎竴娈绠鍗曠殑浠g爜~,...
绛旓細function f = myfunc(c, x, y)f = y - c(1) + x .^ c(2);浠ヤ笂淇濆瓨涓烘枃浠 myfunc.m 鍦ㄥ懡浠よ涓嬭緭鍏ワ細c = lsqnonlin('myfunc', [0 0], [], [], [], x, y);A = c(1)B = c(2)
绛旓細A=magic(n);%浜х敓涓涓n闃堕瓟骞婚樀 H=sum(A);%姣忚鐨勫拰 L=sum(A);%姣忓垪鐨勫拰 DJ=sum(diag(A));%瀵硅绾垮拰 SUM=sum(1:n^2)/n;%n闃堕瓟骞婚樀鐗规湁鐨勫拰 end 锛3锛夛細杩欓鎴戠粰鍑衡滆鏁板悇浣嶆暟瀛椾箣鍜屼负濂囨暟鈥濈殑姹傛硶锛岀粨鍚堜笂闈㈡湁鍒ゆ柇绱犳暟鐨勪唬鐮佽嚜宸卞彲浠ユ眰鍑 璇ユ暟鍚勪綅鏁板瓧涔嬪拰涓哄鏁帮細function...
绛旓細function E = sumM(datain)summ = sum(datain);E = sum(summ);涓婇潰杩欎釜绋嬪簭瑕佹柊寤虹珛涓涓M鏂囦欢锛岀劧鍚庝繚瀛樿捣鏉ョ殑浠ヤ究璋冪敤鐨勶紝涓嬮潰杩欎釜绋嬪簭灏辨槸涓荤▼搴 clc;clear all;n = 20;for i = 1 : n for j = 1 : n if(i == j)a(i, j) = 1;else a(i, j) = 2;end end end xx =...
绛旓細2014-06-26 姹備簲鑺傜偣娼祦璁$畻MATLAB绋嬪簭 2 2014-12-22 MATLAB鐨勭數鍔涚郴缁熸疆娴佽绠楃▼搴 50 2014-11-22 鐢╩atlab璇█鎴朇璇█杩涜鐢靛姏绯荤粺娼祦璁$畻,璁炬兂涓涓畝鍗... 2015-03-26 matlab娼祦璁$畻绋嬪簭涔︾睄鎺ㄨ崘 2016-06-25 姹傚府蹇欏垎鏋愮數鍔涚郴缁熸疆娴佽绠鐨凪ATLAB绋嬪簭 2014-07-07 姹備竴浠絤atlab椋庣數娼祦璁$畻绋嬪簭 3 ...
绛旓細渚嬪;a=[1 2 3 4 5] 锛沚=sum(a)/size(a,1);c=0;for i=1:5 c=(a(i)-b)^2+c;end d=sqrt(c/(size(a,1)-1);disp(d);d鍗冲叾鐨勬柟宸 銆
绛旓細t4.m鍙傝绋嬪簭(鑰冭檻浜嗗浜烘渶楂樸佹渶浣庣瓑鎯呭喌)锛氳鐪嬫噦锛侊紒锛佽兘缂栨渶濂斤紒function t4()clc ---start 鍒濆鍖--- row=input('杈撳叆瀛︾敓浜烘暟锛');col=input('杈撳叆璇剧▼鏁扮洰锛');score=fix(rand(row,col)*49)+49;xh0=1:row;kch0=1:col;for ii=1:row zcj_pre(ii)=sum_(score(ii,:));...
绛旓細50鍒...閲嶈阿 = =|| function [ans1 ans2 ans3]=fff_sha(C)[m n]=size(C);c1=0.2;c2=0.5;c3=0.8;for i=1:m for j=1:n aaa=C(i,j);if (aaa>=0)&&(aaa<=c1)ans1(i,j)=0;ans2(i,j)=0;ans3(i,j)=1;continue end if (aaa>=c1)&&(aaa<=c2)ans1(i,j)...
绛旓細棣栧厛闇瑕佸憡璇変綘锛屽湪matlab涓锛屽彉閲忕殑涓嬫爣鏄粠1寮濮嬬殑锛岃繖涓鐐瑰拰C璇█鏄笉鍚岀殑锛屼粠0寮濮嬪皢瑕佹姤閿欙紱鍏舵锛屼綘鐨勯棶棰樿鐨勪笉澶竻妤氾紝n0(i),n1(i)鏄粰瀹氱殑鍊煎悧锛熷彟澶栵紝鍦ㄧ浜屼釜绾︽潫鏉′欢涓紝鈥滃浜庝换鎰廼鐨勫崄涓涓彇鍊间腑鐨勪竴涓湁鈥濊繖鍙ヨ瘽鏈夋涔夛紝鏄繀椤鏈変竴涓杩樻槸鍏ㄩ儴閮芥槸鍛紵鑰宯0*y0(i)鍜宯1*y1(i...
绛旓細x0=5;y0=5;R=4; % 瀹氫箟鍦嗗績鍜屽崐寰 alpha=0:pi/50:2*pi; %瑙掑害[0,2*pi]x=x0+R*cos(alpha);y=y0+R*sin(alpha);plot(x,y,'-','LineWidth',2)ylim([0,10]);hold on axis equal n=10;alpha1 = 0:2*pi/n:(2*n-2)*pi/n; %姣忛殧360/n搴︼紝鐢诲嚭鐩稿簲鐨勭洿绾 x1=...