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

採用された回答
ANKUR KUMAR
2018 年 10 月 8 日
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 件のコメント
Muhammad RSMY
2018 年 10 月 8 日
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.
Muhammad RSMY
2018 年 10 月 8 日
here is the file, thanks once again
ANKUR KUMAR
2018 年 10 月 8 日
編集済み: ANKUR KUMAR
2018 年 10 月 8 日
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{:}))
Muhammad RSMY
2018 年 10 月 8 日
@ANKUR KUMAR wow you are great.. I really appreciate your kind support,, thanks a lot
ANKUR KUMAR
2018 年 10 月 8 日
編集済み: ANKUR KUMAR
2018 年 10 月 8 日
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.
Muhammad RSMY
2018 年 10 月 8 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
