for loop to create a vector V of the squares
조회 수: 11 (최근 30일)
이전 댓글 표시
Use a for loop to create a vector V of the squares of the numbers -25 through 25.
I am looking for some help to get me started writing the code and help writing it itself. I am unsure of where to even start with this problem. Thanks in advance.
댓글 수: 0
채택된 답변
the cyclist
2019년 9월 16일
Because this is a very basic MATLAB question, and you don't even know how to start, I would recommending watching the MATLAB Onramp tutorial.
댓글 수: 3
the cyclist
2019년 9월 16일
It's a conundrum, because doing this calculation using a for loop is very "anti-MATLAB". "Making a vector of the squares" leaps right to the answer, and can be done in one line without a for loop -- and is actually the best way to do this.
But since your instructor is presumably trying to teach you about for loops ...
I suggest that you first decide on your algorithm, without writing any MATLAB code. Write down the list of steps. The first step might be "create an object with all the values from -25 to 25", for example. Then, convert those steps into MATLAB code.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 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!