How to write to a cell matrix into csv

1 次查看(过去 30 天)
Hi,
I have a cell matrix (contains numeric values and text). My first row is the column headings. When I write to csv file using "csvwrite" or "xlxwrite", part of first row headings are missing (just empty). Please suggest me how to overcome this.
Sincerely, Mekala
  2 个评论
Renato Agurto
Renato Agurto 2016-1-7
Can you post your cell (or enough of it to reproduce your problem) and the command you are typing to save it?
Kanakaiah Jakkula
I want to read text files and save the data above the first dotted line and between two dotted line in to csv file. I use the below code, and I use csvwrite(filename,M) command. I think my code itself is wrong. Please kindly help me.
Many thanks in advance.
clc;clear all;
clc
tic
FileList=dir('D:\Mekala_Backupdata\Matlab2010\Filesfolder\Code for files\Textfilesreference\ReadFles/');
j=1;
for i=3:1:(size(FileList)) %%read all files from folder of specified dir
FileName{j}=FileList(i).name;
j=j+1;
%disp(FileName);
end
% for i=1:size(FileName,2)
% FileDate{j} = FileName{j}(00:50);
% end
for j=1:size(FileName,2)
fin=fopen(['D:\Matlab2010\Filesfolder\Code for files\Textfilesreference\Newfiles\Newerfiles/',FileName{j}],'r'); %%opening each files and read each line
m=1;
n=1;
s=1;
t=1;
while ~feof(fin)
tt=fgetl(fin); %Scan all lines
if m>=7 && m<=10
aa1=(tt);
Desc1{m-6,:}=aa1;
end
m=m+1;
if s>=14 && s<=16
aa2=(tt);
Desc1{s-9,:}=aa2; %%Desc1 is File details like name
end
s=s+1;
if n>=18 && n<=18
aa3=(tt);
Desc1{n-10,:}=aa3; %%Desc1 is File details like name
end
n=n+1;
if t>=25 && t<=41
aa=(tt);
Desc{t-24,:}=regexp(aa, ' +', 'split'); %%Desc is data
%
end
t=t+1;
end
for p=1:size(Desc1,1)
Fallreport=regexp(Desc1{1},' +','split');
FallID=regexp(Desc1{2},' +','split');
IINT=regexp(Desc1{3},' +','split');
Rainresult=regexp(Desc1{4},' +','split');
Starttime=regexp(Desc1{5},' +','split');
Endtime=regexp(Desc1{6},' +','split');
LMDName=regexp(Desc1{8},' +','split');
Filedetails{j}{1,1}=Fallreport{3};
Filedetails{j}{2,1}=FallID{3};
Filedetails{j}{3,1}=IINT{3};
Filedetails{j}{4,1}=Rainresult{4};
Filedetails{j}{5,1}=Desc1{5,1}(35:(size(Desc1{5,1},2))-2);
Filedetails{j}{6,1}=Desc1{6,1}(35:(size(Desc1{6,1},2))-2);
Filedetails{j}{7,1}=LMDName{5};
end
for k=1:size(Filedetails,2)
DetailsHTD(:,k)=Filedetails{1,k};
end
for n=1:size(Desc,1)
Data_All{j}{n,1}=strcat(Desc{n}(1,1));
Data_All{j}{n,2}=strcat(Desc{n}(1,2));
Data_All{j}{n,3}=strcat(Desc{n}(1,3));
VList{j}{n,1}=Data_All{j}{n,1};
end
Start_values=[];
End_values=[];
for q=1:size((Data_All),2)
Data_Alltemp=Data_All{1,q};
Data_Allstart=Data_Alltemp(:,2);
Data_Allend=Data_Alltemp(:,3);
Start_values=[Start_values Data_Allstart];
End_values=[End_values Data_Allend];
end
for k=1:size(Data_All{j},1)
Data_Allfinal{j}{k,1}=Data_All{j}{k,2};
Data_Allfinal{j}{k,2}=Data_All{j}{k,3};
final11=strsplit(char(Data_Allfinal{j}{k,2}), ' ');
if (isnan(str2double(char(final11(1)))))
% f31{j}{k,1}=char(final11(1));
f31{j}{k,1}=char(Data_Allfinal{j}{k,2});
else
f31{j}{k,1}=str2double(char(final11(1)));
end
end
status = feof(fin);
fclose(fin);
end

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2016-1-9
  2 个评论
Walter Roberson
Walter Roberson 2016-1-10
You cannot do it using csvwrite(). csvwrite() cannot write strings. dlmwrite() cannot write strings. You need to fopen/fprintf/fwrite. Or if you have MS Windows and Excel installed then you can xlswrite() while requesting a .csv file as output.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by