Effacer les filtres
Effacer les filtres

how to plot a piecewise function?

2 vues (au cours des 30 derniers jours)
Leonardo Wayne
Leonardo Wayne le 5 Mai 2016
Modifié(e) : Stephen23 le 5 Mai 2016
I am trying to plot the function below using the following code but it is not correct. help?
  1 commentaire
Stephen23
Stephen23 le 5 Mai 2016
Modifié(e) : Stephen23 le 5 Mai 2016
@Mohammad Abdalnasir Khalid Al-Hiyali: Please do not paste images of code: paste the code as text and then format it correctly using the {} Code button.

Connectez-vous pour commenter.

Réponses (1)

Star Strider
Star Strider le 5 Mai 2016
It would be best for you to copy your code, paste it to yout Question, and then use the {}Code button to format it.
You can replace your entire if block by one statement that multiplies a logical-index vector by the values of the function in that region. Use this assignment to ‘y’ instead:
y = (x<0.5).*(m*x+b) + ((x>=0.5) & (x<30.5)).*(upper_limit_y) + (x>30.5).*(-m*x+b);
I tested it and it works.

Catégories

En savoir plus sur Visual Exploration dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by