I want to create a conditional function
146 views (last 30 days)
Show older comments
Deniz Bozdogan on 23 Feb 2021
Commented: Steven Lord on 21 Mar 2023 at 14:33
When i try to create the following function with n=[-25:25] the value of x1 shows as x1=-3
What can i do to make the function work?
KALYAN ACHARJYA on 23 Feb 2021
Edited: KALYAN ACHARJYA on 23 Feb 2021
You have not completed the Code, If you are beginner Do Google MATLAB Onramp
Read about if Else, For Loop and Logical Indexing MATLAB
Using if else and loop
if n(i)>=0 && n(i)<=8
Without using loop and if else (Recommended)
x1(n>=0 & n<=8)=-3;
Steven Lord on 21 Mar 2023 at 14:33
@SRADHARAM SWAIN This doesn't appear to be closely related to the original topic of this question. Please ask it as a new question (using the Ask link near the top of this page.) When you do, please show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
More Answers (0)
Find more on Loops and Conditional Statements 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!