Parse error: usage might be invalid MATLAB syntax
조회 수: 64 (최근 30일)
이전 댓글 표시
Hi, I am doing a really simple homework assignment:
"Create a file named matlabprog.m . In this program, you should create two arrays A and B. A should hold the numbers 1 through 4. B should hold the numbers 4 through 1.
You should then add A and B together, storing the result in a new array C.
After performing these array operations, you should use disp() to output the array (i.e. to output array C you would write disp(C); )
Then calculate sin(A) and store the resulting array in a new array named D. You should output array D using disp()
Each command should be on its own line and should end with a semicolon. Execute this file in matlab by typing the following into the prompt: >> matlabprog"
So this is what I did:
diary('matlabprog.m')
A = [1,2,3,4];
B = [4,3,2,1];
C = (A+B);
disp(C);
5 5 5 5
D = (sin(A));
disp(D);
0.8415 0.9093 0.1411 -0.7568
diary('off')
However, when I try to do the last step of the assignment of entering matlabprog into matlab, this comes up:
"Error: File: matlabprog.m Line: 5 Column: 12
Unexpected MATLAB expression."
So when I looked at the messages from my code these errors came up:
5 Parse error at 5: usage might be invalid MATLAB syntax.
9 Parse error at '0.9093': usage might be invalid MATLAB syntax.
How do I fix this, and is there anything else wrong with what I did? Thanks.
댓글 수: 0
채택된 답변
Andrew Newell
2014년 12월 2일
You included the answers in the file, and MATLAB is trying to interpret them as commands. My guess is that you don't need the diary commands either, so a working file would look like this:
A = [1,2,3,4];
B = [4,3,2,1];
C = (A+B);
disp(C);
D = (sin(A));
disp(D);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Argument Definitions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!