Execute code from top to bottom

5 visualizzazioni (ultimi 30 giorni)
Erick Del Real
Erick Del Real il 13 Lug 2018
Commentato: Erick Del Real il 13 Lug 2018
Hello,
I was under the impression that MatLab executes code from top to bottom, I am trying to update a TEXT box in GUIDE so that when you press the button "Import Excel Document" it will give a status of what the code is doing.
In other words I press the button and the status box goes from "reading data" , "Data Loaded", "Proceed to Plot"
But what I want its to say the first status "reading data" then execute the command to read data from excel document so that if its a long excel document and its going to take a while the status box still says "reading data". Once the excel is loaded I want the status box to change to "Data Loaded" wait a second then change to "Proceed to Plot".
What my code does now, it imports the excel document first (so it takes a while with the text box blank or with the last status) and once the excel document is done being imported then it updates the status box.
%EXCECUTES WHEN BUTTON ONE IS PRESS
%
function pushbutton1_Callback(hObject, ~, handles)
%SETS UP GLOBAL VARIABLES SO THAT OTHER FUNCTIONS CAN CALL ON THEM
global data1
global header1
global filename1
global data2
global header2
global filename2
%UPDATES THE STATUS BOX
status = 'Reading data';
set(handles.editStatus, 'String', status);
%INPORTS FROM EXCEL DOCUMANT AND PARSES ARRAYS, MATRICES, ETC
filename1 = get(handles.filename, 'String');
sheet = (str2num(get(handles.editSheet, 'String')));
[num txt raw] = xlsread(filename1,sheet);
%INPORTS FROM EXCEL DOCUMANT AND PARSES ARRAYS, MATRICES, ETC
filename2 = get(handles.edit8, 'String');
sheet2 = (str2num(get(handles.edit9, 'String')));
[num2 txt2 raw2] = xlsread(filename2,sheet2);
data1 = num;
l = length(txt(:,1));
header1 = txt;
header1([1:l-1],:) = [];
data2 = num2;
l = length(txt2(:,1));
header2 = txt2;
header2([1:l-1],:) = [];
pause(1);
status = 'Data loaded';
set(handles.editStatus, 'String', status);
pause(1);
status = 'Proceed to plot';
set(handles.editStatus, 'String', status);
set(handles.popupmenu4,'String', header1);
set(handles.popupmenu5,'String', header2);
  1 Commento
Erick Del Real
Erick Del Real il 13 Lug 2018
Modificato: Geoff Hayes il 13 Lug 2018
%EXCECUTES WHEN BUTTON ONE IS PRESS
%
function pushbutton1_Callback(hObject, ~, handles)
%SETS UP GLOBAL VARIABLES SO THAT OTHER FUNCTIONS CAN CALL ON THEM
global data1
global header1
global filename1
global data2
global header2
global filename2
%UPDATES THE STATUS BOX
status = 'Reading data';
set(handles.editStatus, 'String', status);
%INPORTS FROM EXCEL DOCUMANT AND PARSES ARRAYS, MATRICES, ETC
filename1 = get(handles.filename, 'String');
sheet = (str2num(get(handles.editSheet, 'String')));
[num txt raw] = xlsread(filename1,sheet);
%INPORTS FROM EXCEL DOCUMANT AND PARSES ARRAYS, MATRICES, ETC
filename2 = get(handles.edit8, 'String');
sheet2 = (str2num(get(handles.edit9, 'String')));
[num2 txt2 raw2] = xlsread(filename2,sheet2);
data1 = num;
l = length(txt(:,1));
header1 = txt;
header1([1:l-1],:) = [];
data2 = num2;
l = length(txt2(:,1));
header2 = txt2;
header2([1:l-1],:) = [];
pause(1);
status = 'Data loaded';
set(handles.editStatus, 'String', status);
pause(1);
status = 'Proceed to plot';
set(handles.editStatus, 'String', status);
set(handles.popupmenu4,'String', header1);
set(handles.popupmenu5,'String', header2);

Accedi per commentare.

Risposte (1)

Geoff Hayes
Geoff Hayes il 13 Lug 2018
Erick - try calling drawnow after each change to the text in your text control so that it updated immediately on the GUI. For example,
status = 'Reading data';
set(handles.editStatus, 'String', status);
drawnow;
I think that is what you want to happen (and that might not be happening right now).

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Prodotti


Release

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by