Size of matrix changing when input through function
Mostrar comentarios más antiguos
Something odd is occurring when I input a matrix through a function. I have the following in a script:
range = [500,2000];
increment = 100;
duty = range(1):increment:range(2);
It gets passed into the following function:
ODE_output = get_ODE(duty);
and the length of 'duty' within the get_ODE function goes from 16 to 186 columns. Instead of keeping the original matrix it creates a new one with the following size:
duty = 150:10:2000
I know at one point I had changed my conditions to the above, however I do not understand why it keeps reverting to that specific duty matrix.
I've cleared variables and restarted MATLAB numerous times. I've debugged this for a while and the duty matrix isn't called again until the get_ODE function.
Any ideas on why it's happening and how to fix this?
Thanks!
7 comentarios
Guillaume
el 29 de Nov. de 2016
Well, what is the code of get_ODE?
Note that whatever happens in the function get_ODE does not affect the values of the variables in your base workspace (except ODE_Output of course), even if they have the same name.
Domenick Avanzi
el 29 de Nov. de 2016
Editada: Domenick Avanzi
el 29 de Nov. de 2016
Daniel kiracofe
el 29 de Nov. de 2016
I'd suggest you post your code. If not the entire code, at least post a large enough segment that we can run it and reproduce the problem. It's hard to debug "weird" things like this without seeing the whole code.
bio lim
el 30 de Nov. de 2016
When your duty is called by get_ODE, the value of duty will not be changed in your base workspace even if the size of duty changes inside your function. Are you sure, you are missing a part in your script where you mistakenly change your duty variable?
the cyclist
el 30 de Nov. de 2016
I second the suggestion to post code that displays the problem. I recommend trying to distill the code down to the bare minimum that exhibits the behavior. (Often, that process itself will expose the issue.)
Domenick Avanzi
el 1 de Dic. de 2016
Guillaume
el 1 de Dic. de 2016
and that is why you never use plain load. Instead you assign it to a variable and assign the file content as fields of that variable. That way, you never run the risk that load is going to overwrite any of your current variables.
Respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices 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!