Clear Filters
Clear Filters

How can i add 0 or 1 to an vector?

1 view (last 30 days)
Lotte Buser
Lotte Buser on 4 Dec 2017
Answered: KL on 4 Dec 2017
I have to compare the numbers in Pos white the numbers in pos like 30 is greater then 31, then i have to add a number 1 to a new_vector if it's smaller then the previous number i have to add a number 0 te the new_vector
new_vector[]
Pos = [30 31 33 35 38 36 34 32 30 28 26 24 22 22 23 24];
  1 Comment
Jan
Jan on 4 Dec 2017
Edited: Jan on 4 Dec 2017
Your chances to get an answer will grow, if you write it in English.
All I understand are the 3 code lines, but the "close all" is suspicious: It seems like you want to manipulate a vector, so why does closing all figure matters here? I assume it is the typical "cargo cult programming", in which every piece of code starts with the brutal clearing of everything: "clear all; close all; clc".

Sign in to comment.

Accepted Answer

KL
KL on 4 Dec 2017
use diff,
new_vector = [0 diff(Pos)>0]
the answer is
0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1

More Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!