Static text not showing the whole string when loaded with set(handles.text3, 'String', myString)

StackOverflow https://stackoverflow.com//questions/21010172

  •  21-12-2019
  •  | 
  •  

Question

I am using a customer GUI made with GUIDE in conjunction with an arduino and a bluetooth module. Long story short is that I want to be able to read/write over bluetooth to an SD card. This all works fine!

But! When reading back from the sd card, matlab reads the correct data. I can verify this because when printing to the command window it shows the correct data that was on the sd card.

The problem is that when i try set this data to the string of a static text in guide some funny things happen. The static text can be loaded with text, but if i then add more text to the file it's loading from and try to read it out again it still only displays the old data. I know that the string is being updated because as I said when I print to the command it shows the right data.

I have had strange problems with setting static text with this project, Anyone have any ideas to make it easier? Other problems I have had are setting the string in the beginning of a callback function but the text not actually being updated until after the callback has executed the whole function or thrown an error or whatnot.

Was it helpful?

Solution 2

Problem was no drawnow so matlab didn't draw until the whole function was finished.

OTHER TIPS

Is the string too long for the string GUI element, e.g., the string GUI element can only hold 5 lines, and you're trying to display 6, then 7, etc. ?

Matlab does not automatically produce scroll bars on static text. See http://www.mathworks.com/matlabcentral/newsreader/view_thread/148773 for a discussion of alternatives. What I do (courtesy of a co-worker showing me this) on real-time log displays is (assuming this is in a loop) this, with TxtMssg being my text "box" and rec_line being the line I read from the serial port.

try
    % Determine NumLines empirically for your font, font size, and static text size
    NumLines = 21;
    % Get the contents of the static text box, make a cell if necessary
    Mssg = get(handles.TxtMssg, 'string');
    if iscell(Mssg) == 0
        Mssg={Mssg};
    end
    % Cat on the newly received line
    Mssg = [Mssg; rec_line];
    % trim to length of textbox, last NumLines rows only
    if length(Mssg) > NumLines
        Mssg = Mssg((end-NumLines+1):end);
    end
    % Write Mssg, with a strtrim() in case of any trailing newlines
    set(handles.TxtMssg, 'string', strtrim(Mssg));
catch err
    % Error handling
end

I recommend using try/catch/end with datalogging type applications to prevent a glitched communication from crashing the whole program.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top