Memo/Matlab

Matlab function : Text Area(History log) updater

_Ju 2022. 8. 1. 20:36

When you want to update the 'Text Area',

You can use this function.  (This can be used as a history log function)

 


#Fucntion

%// how to call function
app.TextArea.Value = LogUpdater(app.TextArea.Value, 'Hello, World')



%// Below is the function
function [StringSet_New] = LogUpdater(StringSet_Old, Message)

	if (isa(Message, 'char'))
     	MaxLine = 1000;
        temp = StringSet_Old;
        [CurMaxLine, ~] = size(temp);
        
            %// The first line is replaced with an empty cell
            if (CurMaxLine >= MaxLine)
                temp(1) = [];
                CurMaxLine = CurMaxLine - 1;
            end
        
            %// If this is the first line, overwrite the first line
            if (CurMaxLine == 1 && isempty(temp{1, 1}))
                temp{CurMaxLine, 1} = strcat('  >>', Message);
            else
                temp{CurMaxLine + 1, 1} = strcat('  >>', Message);
            end
        
        StringSet_New = temp;
        
    elseif isa(Message, 'cell')
        StringSet_New = [StringSet_Old; Message];
    else
        StringSet_New = StringSet_Old;
    end
end

 

#Matlab

#Matlab App Designer