Pause code while importing data

Hello everyone,
I'm developing a code that will allow the user to imprt whatever data using uiimport command. The data that this code will see will always have the same variables but the problem I run into is that once the data is imported, the code (I think) is not recognizing anything and throws errors. I think the code is continuing to run while the user is importing data which wouldn't allow matlab to see the variables imported.
I am thinking that having an option to run the code at a strategic point will solve the problem but I'm having no luck.
I currently have:
clear;
clc;
uiimport('-file')
while (1)
m=input('Do you want to continue, Y/N [Y]:','s')
if m=='N'
break
end
end
plot(Time, TGTSpeed)

回答 (1 件)

Jos (10584)
Jos (10584) 2018 年 2 月 12 日

0 投票

Using an output of uiimport will stall execution of later code.
S = uiimport('-file')
disp('Import finished.')
% and check for the existence of the fields
needed_var = 'X' ;
if ~isfield(S, needed_var)
error('You should have imported a variable named "%s".', needed_var)
end
disp('Import succeeded') ;

4 件のコメント

Dylan Mecca
Dylan Mecca 2018 年 2 月 12 日
When I run what you have written up, I get an error saying: Undefined function or variable 'S'.
Do you know why it sends this error?
Walter Roberson
Walter Roberson 2018 年 2 月 12 日
Could you confirm that you have the line
S = uiimport('-file')
Dylan Mecca
Dylan Mecca 2018 年 2 月 12 日
Confirmed. I will attach a screenshot as well. Would running 2014a cause this issue?
Jos (10584)
Jos (10584) 2018 年 2 月 12 日
First: fix the lowercase S /capital s !!
The error seems to arise from uiimport having problems importing the data properly and has little to do with my code.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeText Data Preparation についてさらに検索

質問済み:

2018 年 2 月 12 日

コメント済み:

2018 年 2 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by