Size of matrix changing when input through function

7 vues (au cours des 30 derniers jours)
Domenick Avanzi
Domenick Avanzi le 29 Nov 2016
Commenté : Guillaume le 1 Déc 2016
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 commentaires
Domenick Avanzi
Domenick Avanzi le 1 Déc 2016
Thank everyone. I actually figured it out. In my get_ODE function I was calling on a .mat file, however when I initially created the .mat it saved the entire workspace instead of the variables I wanted. This explains why it was reverting to previous workspace variables.
Guillaume
Guillaume le 1 Déc 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur App Building dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by