Read table in .txt to MATLAB
10 views (last 30 days)
Show older comments
Karl Zammit
on 17 Apr 2021
Commented: Karl Zammit
on 19 Apr 2021
I have the following .txt fil and wish to save the columns seperately for further polar extrapolation. However, the following code is resulting in some funny values.
I appreciate any help. I think I am reading the data wrong as I dont fully understand the concept.
Thanks in advance.
%Read data file: Drag and Lift Coeff.
saveFlCdCl = 'Save_CdCl.txt'; %File name
finputCdCl = fopen(saveFlCdCl); %Open file for reading
dataBuffer = textscan(finputCdCl, '%f %f %f ', 'CollectOutput', 1, ... %Read data from file
'Delimiter', '', 'HeaderLines', 12);
%Get values
PolarAoA=dataBuffer{1}(:,1);
PolarCl=dataBuffer{1}(:,2);
PolarCd=dataBuffer{1}(:,3);
fclose(finputCdCl); %Close file
0 Comments
Accepted Answer
Walter Roberson
on 19 Apr 2021
%Read data file: Drag and Lift Coeff.
saveFlCdCl = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/586711/Save_CdCl.txt'; %File name
t = readtable(saveFlCdCl, 'readvariablenames', false, 'headerlines', 12);
t.Properties.VariableNames = {'alpha', 'CL', 'CD', 'CDp', 'CM', 'Top_Xtr', 'Bot_Xtr'};
t(1:5,:)
t(end-4:end,:)
More Answers (1)
David Hill
on 17 Apr 2021
t=readtable('Save_CdCl.txt');
alpha=t.alpha;
names=t.Properties.VariableNames;
for k=1:length(names)
writetable(t(:,k),names{k});
end
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!