How to write to a cell matrix into csv

조회 수: 1 (최근 30일)
Kanakaiah Jakkula
Kanakaiah Jakkula 2016년 1월 7일
댓글: Walter Roberson 2016년 1월 10일
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
Kanakaiah Jakkula 2016년 1월 8일
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
Kanakaiah Jakkula
Kanakaiah Jakkula 2016년 1월 9일
Sir, It wont solve my problem
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개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by