How to use a variable as an 'importdata' string

2 ビュー (過去 30 日間)
Alex
Alex 2017 年 7 月 25 日
コメント済み: Alex 2017 年 7 月 25 日
The following line works fine.
unformatteddata = importdata('neutral.prf', DELIMITER, HEADERLINES);
When I make a variable with 'neutral.prf' as the string, importdata (the last line) fails to find the file.
prf_name= 'neutral';
prf_ext = '.prf';
prf_string(1,1) = strcat(prf_name, prf_ext);
unformatteddata = importdata(prf_string(1,1), DELIMITER, HEADERLINES);
  1 件のコメント
Alex
Alex 2017 年 7 月 25 日
I resolved the error by using:
unformatteddata = importdata(prf_string{1}, DELIMITER, HEADERLINES);

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

回答 (1 件)

Prasanth Sunkara
Prasanth Sunkara 2017 年 7 月 25 日
Hi Alex,
The issue is not with the "importdata" function.
The below command which you used to concatenate the two char arrays should throw a Dimension mismatch error.
>> prf_string(1,1) = strcat(prf_name, prf_ext);
I do not see the need to use array indexing here.
Just use,
>> prf_string = strcat(prf_name, prf_ext);
I believe that would solve your issue.
PS: Refer this link on how to work with character arrays & strings.
  1 件のコメント
Alex
Alex 2017 年 7 月 25 日
This caused the same error, "??? Error using ==> importdata at 136 Unable to open file." I resolved the error by using:
unformatteddata = importdata(prf_string{1}, DELIMITER, HEADERLINES);

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

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by