What is the best way to display a large text file in MATLAB GUIDE?

后端 未结 3 1860
甜味超标
甜味超标 2021-01-03 11:34

How can a MATLAB GUIDE control be used to display the contents of a text file in a GUI? The text file may be very long or very wide so it should have the ability to have ver

3条回答
  •  轮回少年
    2021-01-03 11:51

    Here is my solution for a generic text file called "textfile.txt":

        f = figure('menu','none','toolbar','none');
        fid = fopen('textfile.txt');
        ph = uipanel(f,'Units','normalized','position',[0.4 0.3 0.5 0.5],'title',...
            'Display window');
        lbh = uicontrol(ph,'style','listbox','Units','normalized','position',...
            [0 0 1 1],'FontSize',9);
    
        indic = 1;
        while 1
             tline = fgetl(fid);
             if ~ischar(tline), 
                 break
             end
             strings{indic}=tline; 
             indic = indic + 1;
        end
        fclose(fid);
        set(lbh,'string',strings);
        set(lbh,'Value',1);
        set(lbh,'Selected','on');
    

提交回复
热议问题