I want to load multiple text files into variable cell array

2 ビュー (過去 30 日間)
Vinay Killamsetty
Vinay Killamsetty 2019 年 8 月 28 日
コメント済み: Vinay Killamsetty 2019 年 8 月 30 日
Hi
I want to load multiple text files into call array variable and then read the data from it and store them in different variables
For one text file I have followed code given below:(The example text file is uploaded)
filename = 'G:\Matlab/PhaseOneLay Lambda0.2.txt';
startRow = 7;
formatSpec = '%19f%32f%f%[^\n\r]';
fileID = fopen(filename,'r');
textscan(fileID, '%[^\n\r]', startRow-1, 'WhiteSpace', '', 'ReturnOnError', false, 'EndOfLine', '\r\n');
dataArray = textscan(fileID, formatSpec, 'Delimiter', '', 'WhiteSpace', '', 'TextType', 'string', 'ReturnOnError', false);
fclose(fileID);
Phase_table_HFSS = table(dataArray{1:end-1}, 'VariableNames', {'W1mil','ang_degSFP12FP12deg','ang_degSFP22FP12deg'});
clearvars filename startRow formatSpec fileID dataArray ans;
Phase_HFSS = table2array(Phase_table_HFSS);
But how can I load more text files and access their data in the similar way

採用された回答

KSSV
KSSV 2019 年 8 月 29 日
files = dir('*.txt') ;
N = length(files) ;
iwant = cell(N,1) ;
for i = 1:N
filename = files(i).name ;
startRow = 7;
formatSpec = '%19f%32f%f%[^\n\r]';
fileID = fopen(filename,'r');
textscan(fileID, '%[^\n\r]', startRow-1, 'WhiteSpace', '', 'ReturnOnError', false, 'EndOfLine', '\r\n');
dataArray = textscan(fileID, formatSpec, 'Delimiter', '', 'WhiteSpace', '', 'TextType', 'string', 'ReturnOnError', false);
fclose(fileID);
Phase_table_HFSS = table(dataArray{1:end-1}, 'VariableNames', {'W1mil','ang_degSFP12FP12deg','ang_degSFP22FP12deg'});
clearvars filename startRow formatSpec fileID dataArray ans;
Phase_HFSS = table2array(Phase_table_HFSS);
iwant{i} = Phase_HFSS ;
end
  2 件のコメント
Vinay Killamsetty
Vinay Killamsetty 2019 年 8 月 30 日
Thank you very much.
Vinay Killamsetty
Vinay Killamsetty 2019 年 8 月 30 日
Hi
I want to select multiple text files using Uigetfile into call array variable using loop and then read the data from it and store them in different variables
so that I can select required no of files each time and automatically load the file into different cells by running a loop for selected no.of files.
Can you help me how to change the above code.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by