필터 지우기
필터 지우기

String values change when leaving method

조회 수: 1 (최근 30일)
Ethan Goldstein
Ethan Goldstein 2020년 5월 7일
답변: Ethan Goldstein 2020년 7월 2일
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
Ethan Goldstein
Ethan Goldstein 2020년 5월 11일
Hi Steven, I am wondering if you have had a chance to look into this issue, as I am still unable to figure it out.
Ameer Hamza
Ameer Hamza 2020년 5월 12일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

Ethan Goldstein
Ethan Goldstein 2020년 7월 2일
The problem ended up being I had only allocated one memory location for the string, but pointed at it with multiple instances of different objects. I did not realize I had setup my code to do. This is why I had this problem.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by