Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Why is there a syntax error for my code?

1 回表示 (過去 30 日間)
Tyler
Tyler 2020 年 4 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
>> %% 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

回答 (1 件)

per isakson
per isakson 2020 年 4 月 5 日
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!

Translated by