Parse error: usage might be invalid MATLAB syntax
64 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adam
el 2 de Dic. de 2014
Editada: Andrew Newell
el 2 de Dic. de 2014
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 comentarios
Respuesta aceptada
Andrew Newell
el 2 de Dic. de 2014
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Argument Definitions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!