基于Matlab的程序,其中输出包括输入行的总和 [英] matlab based program where output comprises of sum of rows of input

查看:62
本文介绍了基于Matlab的程序,其中输出包括输入行的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让给定矩阵为:

  c=[5.24 5.19 5.07 4.36;
     5.39 5.44 5.38 5.32;
     5.58 5.12 6.05 4.02]

我想计算输出矩阵,使得输出矩阵的第一行与c的第一行相同,然后输出矩阵的第二行为c的前两行之和,第三行为c的三行之和.如何为此编写一个matlab代码.

I want to compute the output matrix such that first row of output matrix is as it is first row of c, then second row of output matrix is sum of first two row of c and third row is sum of three rows of c. How to write a matlab code for this.

推荐答案

使用Matlab的累积总和函数:

use Matlab's cumulative sum function:

ans = cumsum(c);

这篇关于基于Matlab的程序,其中输出包括输入行的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆