Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
16 views (last 30 days)
Show older comments
%New Component
newName=input('Enter name of new component: ','s');
Name{length(Name)+1}=newName; %adding new component
newCur=input('Enter Current values corresponding to the 5 voltages for the new component in mA:'); %%THIS IS WHERE THE ERROR IS POINTED OUT
CurData=[CurData;newCur]; %appending row of current values for new component
MaxCur=max(max(CurData(2:end,:)));
[R,C]=find(CurData(2:end,:)==MaxCur);
fprintf('Maximum Current = %d mA\n',MaxCur)
fprintf('At voltage = %d V\n',CurData(1,C))
fprintf('For %s\n',Name{R})
I have this code and it give me the error: Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses. At the Line that is labeled. What am I missing?
Answers (1)
Walter Roberson
on 28 Jun 2020
If the user enters a vector of numbers separated by spaces or commas, in response to an input() statement that does not have an 's', then that a syntax error for input()
... I was certain it didn't used to work that way, but now that I go back to test, it seems to have been true since at least R2015b.
So... use the 's' option to input, and parse the result such as with sscanf() . And make sure to count the number of values before trying to do the next line, as the user might not have entered enough values.
0 Comments
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!