Read table in .txt to MATLAB
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2021-4-19
%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,:)
更多回答(1 个)
David Hill
2021-4-17
t=readtable('Save_CdCl.txt');
alpha=t.alpha;
names=t.Properties.VariableNames;
for k=1:length(names)
writetable(t(:,k),names{k});
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!