MATLAB Not Assigning Variable
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
OK, so I have no idea what is going on here. I have been debugging a MATLAB UI I wrote with the help of GUIDE, and it appears MATLAB is simply refusing to assign a variable I tell it to. I have a variable called handles.connected_port, which is an empty serial port object (initially), as you can see below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/167126/image.png)
I also have a serial port that I created in scanning through all the available serial ports using seriallist I have named 'p'.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/167127/image.png)
So far so good. However, when I execute the line of code
handles.connected_port = p;
absolutely nothing happens. In debug mode, in the line after that code is called, handles.connected_port is completely unchanged (see first figure) on the line immediately after execution. This feels like some serious non-determinism and I truly have no clue what's going on. MATLAB simply refuses to assign a variable to its proper value. This is perhaps the most bizarre error I've ever encountered. Is there something silly I'm missing?
0 comentarios
Respuestas (1)
Walter Roberson
el 11 de Sept. de 2017
Why would p be changed by assigning it to handles.connected_port ?
Note: if you are assigning to handles.connected_port inside a function, remember that only the local handles.connected_port would be affected. If you want to change the "master copy", you would need to use
guidata(hObject, handles)
to force it to update.
2 comentarios
Steven Lord
el 11 de Sept. de 2017
Where is the handles structure that you have open in the Workspace browser located? Remember that handles is a struct array and as such uses value semantics. If you're inspecting the handles structure in the base workspace or some workspace other than the one in which you updated it, that will not change (even if you update the "master copy") until you explicitly "refresh" it using guidata.
It's like the handles structure is your credit card bill. Paying your bill will update the "master copy" in the credit card company's records, but it won't change the physical printed bill in your hand until you print out a new copy from your credit card company's website or they print out and send you an updated bill.
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!