
举个例子,希望有所帮助。 代码 clc; clear all; close all; % 载入xls文件 [num, txt, row] = xlsread('c:\\test\\testxls'); apple = num(:, 1); % apple列数据 numlimt = 3; % 阈值 ind = find(apple > numlimt); % 寻找所在的行 num(ind, :) % 显示 结果 ans = 4 3 4 5 4 2 >>
function
linear_fit %最小二乘法拟合直线
clear;
clc;
prompt={'Name
of data file'};
title='Linear_fit';
lineNo=2;
def={'Linearfitdat'};
outval=inputdlg(prompt,title,lineNo,def);
if
isempty(outval)==1,return,end
filename=outval{1};
data=load(filename);
x=data(:,1);
y=data(:,2);
[a,b]=linearfit(x,y);
yy=a+bx;
func=['y=',num2str(a),'+',num2str(b),'x'];
plot(x,y,'bx','markersize',10);
hold on
plot(x,yy,'r-','linewidth',15)
xlabel('t(\year)');
ylabel('S(\mm)');
text(x(2),yy(length(yy)-1),func)
function
[a,b]=linearfit(x,y)
xy=xy;
x2=x^2;
x_mean=mean(x);
y_mean=mean(y);
xy_mean=mean(xy);
x2_mean=mean(x2);
b=(xy_mean-x_meany_mean)/(x2_mean-x_mean^2);
a=y_mean-bx_mean;
return
matlab里有一个函数isprime,是用来判断一个数a是不是素数。x=isprime(a),如果a是素数则x等于1,否则等于0;你要是求素数的话用一个for语句就行了,给你写了个m文件,求1到n之间所有素数:
n=input('enter data n:');
j=1;
for i=1:n
if isprime(i)
x(j)=i;
j=j+1;
end
end
x
你给出的是C语言程序吧,matlab也是一样的,只不过数组的编号是从1开始的,而且语法有些不同。
t(1)=0
s(1)=0
B(1)=0
for n=2:160
x(n)=z600028;
t(n)=x(n)2/13+t(n-1)11/13
s(n)=x(n)2/27+s(n-1)25/27
A(n)=t(n)-s(n)
B(n)=A(n)2/10+B(n-1)8/10
end
function xpbombs(arg1,arg2,arg3)
%XPBOMBS Play the minesweeper game
% There are 13 bombs hidden in the mine field Try to flag them
% and uncover all of the other spaces without getting blown up
% In each non-bomb square is printed the number of adjacent
% squares which contain bombs
%
% Use the FLAG button to toggle in and out of flag mode When
% in flag mode, clicking on any covered square places a flag on it
% Clicking on any flag removes it
%
% At any time during the game, the number of remaining unflagged
% bombs (assuming every flag is on a bomb) is shown in the upper left
%
% NEW stops the game and creates a new minefield
%
% CLOSE closes the game window
% Copyright 1984-2015 The MathWorks, Inc
persistent h minefield cntmines rows cols t nummines remaining
persistent HEIGHT WIDTH BWIDTH BHEIGHT textHndl
persistent flagHndl bomb hidden flag hb nhb hflag
if nargin < 1,
arg1 = 'start';
end;
if strcmp(arg1,'start') ;
rows = 8; % 16;
cols = 8; % 30;
nummines = 13; % 99;
BWIDTH = 35;
SWIDTH = 0;
BHEIGHT = 35;
SHEIGHT = 0;
WIDTH = BWIDTH + SWIDTH;
HEIGHT = BHEIGHT + SHEIGHT;
程序接口
新版本的MATLAB可以利用MATLAB编译器和C/C++数学库和图形库,将自己的MATLAB程序自动转换为独立于MATLAB运行的C和C++代码。允许用户编写可以和MATLAB进行交互的C或C++语言程序。
另外,MATLAB网页服务程序还容许在Web应用中使用自己的MATLAB数学和图形程序。MATLAB的一个重要特色就是具有一套程序扩展系统和一组称之为工具箱的特殊应用子程序。工具箱是MATLAB函数的子程序库,每一个工具箱都是为某一类学科专业和应用而定制的,主要包括信号处理、控制系统、神经网络、模糊逻辑、小波分析和系统仿真等方面的应用。
以上就是关于matlab怎么编写目标函数的程序全部的内容,包括:matlab怎么编写目标函数的程序、如何编写matlab程序、MATLAB中如何编写求素数的程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)