函数求和代码 matlab,一个简单求和函数的matlab实现(带程序耗时功能)

function [ sum_m ] = diffSum( )

%function [ sum_m ] = diffSum(beginning ,ending,dim)

tic%用来计时的,没什么作用,纯粹是为了跟大家讲解这么个用法

%利用while,for等语言实现简单求和运算,作者:nicolashe,2016年5月9日 11:13:26

% begin代码起始数,end代表终止数,都是闭口的,dim表示选择用的模式1表示

%表示采用while,2表示采用for,为了展示给你们看,采用switch,也可以使用if实现模式的选择,默认采用1

%%下面利用switch实现选择

%实际上我此时已经忘记了switch的语法,但是不要紧,可以即学即用啊,我查帮助文档得知

%{

help switch

switch Switch among several cases based on expression.

The general form of the switch statement is:

switch switch_expr

CASE case_expr,

statement, ..., statement

CASE {case_expr1, case_expr2, case_expr3,...}

statement, ..., statement

...

OTHERWISE,

statement, ..., statement

END

The statements following the first CASE where the switch_expr matches

the case_expr are executed. When the case expression is a cell array

(as in the second case above), the case_expr matches if any of the

elements of the cell array match the switch expression. If none of

the case expressions match the switch expression then the OTHERWISE

case is executed (if it exists). Only one CASE is executed and

execution resumes with the statement after the END.

The switch_expr can be a scalar or a string. A scalar switch_expr

matches a case_expr if swit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值