Matlab,替代创建额外的矢量吗? [英] Matlab, alternative to creating an extra vector?

查看:82
本文介绍了Matlab,替代创建额外的矢量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这个,我会报错

If I have this I get an error

sum(vector) == cumsum(vector)(length(vector))

>> Error: ()-indexing must appear last in an index expression.

我知道我可以做到:

Vec1 = cumsum(mat);
sum(mat) == Vec1(length(mat))

这将返回逻辑1.

是否可以将所有内容都放在一行上?

Is there an alternative to get everything on a single line?

推荐答案

好吧,如果您有绝对的决心要一行完成,

Well, if you are absolutely determined to do it in one line,

sum(vec) == subsref(cumsum(vec),struct('type','()','subs',{{numel(vec)}}))

但这是对 subsref 的严重滥用.通常用于重载自定义类中的下标运算符(即{}().).

这篇关于Matlab,替代创建额外的矢量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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