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

 Réponse acceptée

ANKUR KUMAR
ANKUR KUMAR le 8 Oct 2018
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 commentaires

Muhammad RSMY
Muhammad RSMY le 8 Oct 2018
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
ANKUR KUMAR le 8 Oct 2018
Modifié(e) : ANKUR KUMAR le 8 Oct 2018
Please attach your .txt file.
Muhammad RSMY
Muhammad RSMY le 8 Oct 2018
here is the file, thanks once again
ANKUR KUMAR
ANKUR KUMAR le 8 Oct 2018
Modifié(e) : ANKUR KUMAR le 8 Oct 2018
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
Muhammad RSMY le 8 Oct 2018
@ANKUR KUMAR wow you are great.. I really appreciate your kind support,, thanks a lot
ANKUR KUMAR
ANKUR KUMAR le 8 Oct 2018
Modifié(e) : ANKUR KUMAR le 8 Oct 2018
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
Muhammad RSMY le 8 Oct 2018
Oh Thanks once again

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by