等待变量不存在MATLAB

时间:2016-06-20 21:09:47

标签: matlab wait exists

我需要暂停程序,直到创建变量。我指向数据文件,然后打开uimport指定数据范围。此时我必须暂停程序,直到创建变量。

%find file
[FileName,PathName] = uigetfile({'*.xls;*.xlsx', 'Excel files(*.xls, *.xlsx)'},'Укажите Excel-файл с данными');
%open import wizard
uiimport(strcat(PathName, FileName));
% here i need to suspend the program until the variable is created

1 个答案:

答案 0 :(得分:2)

调用text_above = "..." # this is the text above pat_str = '<a href="(\d+)">\n(.+)\n<span class' pat = re.compile(pat_str) # following line is supposed to return the numbers from the 2nd line # and the string from the 3rd line for each repeating sequence list_of_tuples = re.findall(pat, text_above) for t in list_of tuples: # supposed to print "11111 -> blah blah 111" print(t[0], '->', t[1]) 时必须指定输出变量。如果您执行此操作,则在uiimport完成之后(用户选择要导入的数据与否)之后,您的uiimport调用之后不会执行任何行。

uiimport

如果出于某种原因, 需要等到变量存在,您可以使用data = uiimport(fullfile(PathName, FileName)); % Do stuff with data disp(data.value) 循环与while结合使用,但通常这是一个标记程序设计不佳。

exist

<强>更新

如果您只是阅读excel文件,则可能更容易使用while ~exist('variablename', 'var') % Do something that may define the variable end 来执行此操作:

xlsread