how to load dat file without header?
显示 更早的评论
hi friends
could you please help me upload dat file without header, also I would like to get similar arrangement of data, as you see there is some rows have extra columns
thanks

采纳的回答
Since you have not attached any sample file, I am giving you an example with a attached file.
A=importdata('sample.txt');
A.data
7 个评论
Thanks @ANKUR KUMAR for your reply, but still I am facing the problem cause the headers for 4 columns while data for 6 columns and 8 columns sometimes
ANKUR KUMAR
2018-10-8
编辑:ANKUR KUMAR
2018-10-8
Please attach your .txt file.
here is the file, thanks once again
Try this one.
clc
clear
for kk=2:7
fid=fopen('df.dat');
C = textscan(fid,'%s',1,'delimiter','\n', 'headerlines',kk-1);
C1{kk-1}=strsplit(char(C{1}),' ')
id(kk-1)=length(C1{kk-1});
end
for i=1:length(C1)
C1{i}(length(C1{i})+1:max(id))={''}; %added +1 after length(C1{i})
end
C2=cat(1,C1{:})
If you wish to store in matrix, then put 0 and then convert to matix
for i=1:length(C1)
C1{i}(length(C1{i})+1:max(id))={'0'}; %added +1 after length(C1{i})
end
C2=str2double(cat(1,C1{:}))
@ANKUR KUMAR wow you are great.. I really appreciate your kind support,, thanks a lot
Updated the previous answer. Updated commands are:
C1{i}(length(C1{i})+1:max(id))={''};
and
C1{i}(length(C1{i})+1:max(id))={'0'};
I forgot to add 1 after length(C1{i}).
Sorry for the inconvenience.
Oh Thanks once again
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Simulink 的更多信息
标签
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
