Filter löschen
Filter löschen

How can i add 0 or 1 to an vector?

1 Ansicht (letzte 30 Tage)
Lotte Buser
Lotte Buser am 4 Dez. 2017
Beantwortet: KL am 4 Dez. 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 Kommentar
Jan
Jan am 4 Dez. 2017
Bearbeitet: Jan am 4 Dez. 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".

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KL
KL am 4 Dez. 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

Weitere Antworten (0)

Kategorien

Mehr zu Just for fun finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by