Using loops to perform vector functions
이전 댓글 표시


I'm new to MATLAB and I'm having trouble with my function. I'm trying to call upon a different operation "op" to do subtraction instead of addition but despite entering op as 2 it's still doing addition. Any help is greatly appreciated.
댓글 수: 3
Torsten
2022년 1월 26일
Maybe a2 = 0 ?
Jonathan Lam
2022년 1월 26일
Torsten
2022년 1월 26일
You set op=1 within the function.
채택된 답변
추가 답변 (1개)
KSSV
2022년 1월 26일
0 개 추천
In the function you have given input op which decides wheter to add ot subtract. But you are over writitng the input op inside the code to op = 1. So always the function adds. You need to remove the line op = 1 i.e. ine number 10 in the code.
Also your variable result has to be intiailized before the loop.
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!