Matlab运算子

编程入门 行业动态 更新时间:2024-10-21 14:41:33
本文介绍了Matlab运算子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为明天的累积考试而学习,在上一次考试中我错了以下问题.我希望有人可以向我解释这个问题? (〜m)是什么意思?

I am studying for cumulative exam I have tomorrow and I got the following question wrong on a previous exam. I was hoping someone could explain this question to me? What does (~m) mean?

问题说: 执行以下脚本后,m的值是多少?

The question says: After executing the following script, what is the value of m?

a=1; b=2; m=0; if (~m) m = m+1; if (a-b > 0) m = m+1; else m = m -1; end elseif (m > 1) m = m + 2; else m = m - 2; end

正确答案是0,但是为什么呢?我猜想m = -2

The correct answer is 0, but why? I would have guessed that m = -2

推荐答案

~表示NOT.但是,除非数值等于0,否则所有数值都被视为TRUE.

The ~ means NOT. However, numeric values are all considered TRUE unless they are identically equal to 0.

因此,此逻辑实际执行的命令是:

So, the commands which are actually executed by this logic are:

m = m+1; %Following if (~m) m = m-1; $Following else

此外,代码中还有一个嵌套的if语句.如果您使用了多个级别的缩进,将更易于阅读.

Also, there is a nested if statement in the code. It will be easier to read if you used multiple level indentations.

更多推荐

Matlab运算子

本文发布于:2023-10-14 22:19:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492376.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Matlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!