How to get rid of Warning"Unexpected use of '[' in a scalar context."
33 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Crystal Lee
el 13 de Ag. de 2018
Respondida: David
el 7 de Dic. de 2024
a part of the function has:
if the input A (a vector) matches what is stated, the statement runs.
if A == [1,3,3]
% statement
end
and it gives me this error: 'Unexpected use of '[' in a scalar context. How can I fix this?
2 comentarios
dpb
el 13 de Ag. de 2018
Must be more than that; that code runs w/o any error here...
>> A=3;
>> if A==[1, 3, 3],disp('ok'),end
>> A=[1 3 3];
>> if A==[1, 3, 3],disp('ok'),end
ok
>>
Show us the context including the error message with all the text generated...
Respuesta aceptada
Más respuestas (2)
KSSV
el 13 de Ag. de 2018
When you use A == [1 3 3] ;
With this operator ==, MATLAB expects a scalar value, but the way used here, it gives array as output. So the warning pops out. The way you use, won't work out. YOu need to use the operator == with a scalar value, so the if condition works fine.
5 comentarios
David
el 7 de Dic. de 2024
You may want to use isequal instead of == for that use case.
0 comentarios
Ver también
Categorías
Más información sobre Scope Variables and Generate Names en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!