writing condition function with vector
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Write a function which inputs a vector v and outputs a vector with the indices i which represent a sign change in v.
Write a function which inputs a vector v and outputs a vector with the indices i which represent a sign change in v.
One suggestion is to write conditions on the vector and some kind of shifted version of itself.
please help me writing this function code
2 Commenti
David Hill
il 19 Feb 2020
Look at what this does:
v<0;%turns your vector into ones and zeros.
look at diff() and find() commands.
Risposte (1)
Nishant Gupta
il 24 Feb 2020
Modificato: Rik
il 24 Feb 2020
You can use the followoing logic for writing the function:
x = [1 2 -3 4 -5 -6 7 -9];
product = x(1:end-1).*x(2:end);
res = find(product<0) + 1;
1 Commento
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!