how to return only true statements

2 次查看(过去 30 天)
for example, if I have:
>> e=[1 -7 -1.2 6 -9 19 1.8]
and I want matlab to give me only the true statements for e>0
as in:
e=[1 6 19 1.8]
I tried
>> if e>0 e end
but doesn't do anything.
thanks
  1 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2013-9-27
编辑:Azzi Abdelmalek 2013-9-27
I think you should read the basics of programming. (not necessary Matlab)
if e>0
e
end
What are you expecting when you write
e

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2013-9-27
You mean like this
out = e(e>0)

更多回答(1 个)

Wayne King
Wayne King 2013-9-27
Just do
e>0
You get the following
1 0 0 1 0 1 1
If you want to return the elements
X = e(e>0);

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by