Error is generated while using uigetfile while loading text files manually

1 回表示 (過去 30 日間)
Vinay Killamsetty
Vinay Killamsetty 2019 年 8 月 30 日
編集済み: Vinay Killamsetty 2019 年 9 月 2 日
I have to manually select the files which have to be loaded. Each text file is loaded seperately into different cells "Amplitude"and "phase" cell array by using loop.
The text files contains both text and numerical values. Sample text file is uploaded with this question
The data of half of the files are loaded into "Amplitude" cell array and other half into "phase" cell array.
I have followed this code given below: I am getting errors like
Error using load
Number of columns on line 2 of ASCII file
Error in Current_Impedance_9 (line 8)
file = load(fullfile(PathName,FileName{i}));
How to resolve this problem
  2 件のコメント
dpb
dpb 2019 年 8 月 30 日
編集済み: dpb 2019 年 8 月 30 日
Your input file contains header lines which load cannot deal with.
It's not at all clear why you've got that line in there as you then go on to use textscan that knows how to handle formatted text files.
You're doing way more there in the use of options than the file requires, however...something like
fmt=repmat('%f',1,4);
hdrLines=7;
for i = 1:length(FileName)
fid=fopen(fullfile(PathName,FileName{i})),'r');
dataArray=cell2mat(textscan(fid,fmt,'headerlines',hdrLines));
fid=fclose(fid);
end
should load your data array into a double array of Nx4
I'd suggest you might want to look into using the ML table object however, and readtable.
Vinay Killamsetty
Vinay Killamsetty 2019 年 8 月 31 日
Thanks a lot. This worked perfectly

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by