Info

This question is closed. Reopen it to edit or answer.

Why is there a syntax error for my code?

1 view (last 30 days)
Tyler
Tyler on 4 Apr 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
>> %% User Input
>> phi1=input('Please input the first boundary condition');
Please input the first boundary conditionphi2=input('Please input the second boundary condition');
Please input the second boundary conditionL=input('What''s the length of the domain?');
What's the length of the domain?rho=input('What''s the density of the fluid?');
What's the density of the fluid?K=input('What''s the co-efficient of diffusion?');
What's the co-efficient of diffusion?u=input('What''s the flow velocity?');
What's the flow velocity?nx=input('What''s the number of grid points');
What's the number of grid pointsfprintf('Menu\n1)Central Differencing\n2)Upwind Differencing\n3)Hybr
id Differencing\n4)Power Law\n5)Exit\n\n');
Menu
1)Central Differencing
2)Upwind Differencing
3)Hybrid Differencing
4)Power Law
5)Exit
>> Choice=input('Please input the serial number of the process');
Please input the serial number of the processif Choice==1
parse error:
syntax error

Answers (1)

per isakson
per isakson on 5 Apr 2020
I don't think the problem is with your code, but rather with the users input. input( 'Please input ... ' ) expects an expression (see help on input). ==1 isn't a legal expression. It's when Matlab tries to evaluate ==1 that the error is thrown. A trailing space after the text makes it more readable.
>> Choice=input('Please input the serial number of the process: ');
Please input the serial number of the process: ==1
Error: Invalid use of operator.
>> Choice=input('Please input the serial number of the process: ');
Please input the serial number of the process: 1
>> Choice
Choice =
1
>>

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!