Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
%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?
2 comentarios
dpb
el 28 de Jun. de 2020
>> %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})
Enter name of new component: fred
Unrecognized function or variable 'Name'.
>> Name=[];
>> newName=input('Enter name of new component: ','s');
Name{length(Name)+1}=newName; %adding new component
Enter name of new component: Fred
>> Name
Name =
1×1 cell array
{'Fred'}
>> newCur=input('Enter Current values corresponding to the 5 voltages for the new component in mA:'); %%THIS IS WHERE THE ERROR IS POINTED OUT
Enter Current values corresponding to the 5 voltages for the new component in mA:1:5
>> CurData
Unrecognized function or variable 'CurData'.
>> newCur
newCur =
1 2 3 4 5
>> CurData=[CurData;newCur]; %appending row of current values for new component
Unrecognized function or variable 'CurData'.
>> CurData=[];
>> CurData=[CurData;newCur]; %appending row of current values for new component
>> MaxCur=max(max(CurData(2:end,:)));
>> MaxCur
MaxCur =
0×5 empty double matrix
>>
As the above shows, we can't duplicate as you didn't provide a complete sample test code that reproduces the issue.
If I create an empty variable for the missing ones, I don't get an error.
Not a real good way to write the user input, it would probably be more user friendly to just define a file format and let them edit the data in a file that is then read than have to type in at command line where any typo is fatal...
We'd have to see all the code and the error in context to be able to comment...
Respuestas (1)
Walter Roberson
el 28 de Jun. de 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 comentarios
Ver también
Categorías
Más información sobre Data Distribution Plots 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!