How do I force MATLAB treat my variable 'range' as a variable instead of a function ?
Mostrar comentarios más antiguos
I am doing a project for my sponsor. In the data he gives me, there is a matrix called 'range'. When I use this variable 'range' in my own function, MATLAB always treats it as its build-in function and gives me error. Since I cannot ask my sponsor to change the name of the variable, is there a way to force MATLAB treat 'range' as a variable ?
2 comentarios
Firepanda415
el 2 de Mayo de 2017
Stephen23
el 3 de Mayo de 2017
- Never simply load into the workspace and make variables magically appear in the workspace. Always load into an output argument (which is a structure): S = load(...);
- Do not use the variable name range. Always use which to check if a name is already in use.
Note that if you had load-ed into a structure then this issue would never have occurred!
Respuesta aceptada
Más respuestas (1)
Alessandro
el 2 de Mayo de 2017
0 votos
Simply create a copy of the variable assigning a different name?
3 comentarios
Firepanda415
el 2 de Mayo de 2017
Alessandro
el 2 de Mayo de 2017
Editada: Alessandro
el 2 de Mayo de 2017
I still don't understand the problem, as long as the 'range' variable is correctly indicized in the function. The following MWE works for me:
function [ range ] = test( range )
range = 2*range;
end
if I call
range = [1 2;3 4];
range = test(range)
from the workspace the result is
range =
2 4
6 8
Firepanda415
el 2 de Mayo de 2017
Categorías
Más información sobre Variables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!