String values change when leaving method
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ethan Goldstein
el 7 de Mayo de 2020
Respondida: Ethan Goldstein
el 2 de Jul. de 2020
I am unable to assign string values from one vector to another without what I believe to be pointer errors occuring.
The process:
I assign strings to a string vector:
fileName(k) = string(Filelist(k).name);
I then assign strings from within the string vector to parameters:
obj.channel(i).fileName = fileName(i);
The assignment works as expected, and the strings are all assigned correctly. Upon leaving the method, I print out the values of the strings to console and they a re all completely incorrect! The strings are all the same value and are assigned to the final string value of the string vector.
Instead of the string being:
A B C D E
The string is:
E E E E E
I have a suspicion this has to do with how Matlab assigns pointers and performs garbage cleanup when interacting with multiple scopes/classes. If anybody has a solution to this problem I would greatley appreciate it.
4 comentarios
Ameer Hamza
el 12 de Mayo de 2020
Ethan, the line of codes in your question is different as compared to your comment. You are using custom get and set methods. Is obj.channel(i) an instance of your custom class? Can you show the definition of these get and set method? Preferably, can you share a small standalone example, with simple class definitions so that we can recreate the error?
Respuesta aceptada
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!