Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

matlab sintax

6 views
Skip to first unread message

baltam

unread,
Sep 5, 2012, 6:19:05 AM9/5/12
to
What does this mean?

t = [0, 0, 1, 0, 1, 0, 0, 1, 0];

b=sum((t-[t(2:end),0])==-1);

dpb

unread,
Sep 5, 2012, 9:21:49 AM9/5/12
to
Past it into command widow and work from inside out to see...

(t-[t(2:end),0])
((t-[t(2:end),0])==-1)

BTW, it could be written as

b=sum([-diff(t) 0]==-1);

--

baltam

unread,
Sep 5, 2012, 10:21:07 AM9/5/12
to
dpb <no...@non.net> wrote in message <k27jl0$n1v$1...@speranza.aioe.org>...
Using the Command Window I understand that is a method to count the number of (-1) in the result.
The expression t-[t(2:end),0] executes the difference among each terms of the t vector.
Considering t = [0, 0, 1, 0, 1, 0, 0, 1, 0];
the expression t-[t(2:end),0] gives as result [0 -1 1 -1 1 0 -1 1 0]
so it computes:
0-0 = 0
0-1 = -1
1-0 = 1
and so on

Why didn't I use the Command Window before? :-)
0 new messages