help with xlswrite [char write and blank data]
3 次查看(过去 30 天)
显示 更早的评论
hello currently I am working with a matlab that takes the date of the experience of the folder where it reads some information so for example the folder has the name "2016-11-15 Test 1" and I need to save some information that the program produce in an excel and I am struggling with two things first with the date I have coded like this
Date=deepestFolder(end-16:end-7);
Test=deepestFolder(end-5:end);
xlswrite(['Path\excel.xlsx'],Date, Test,'C2');
so, date is going to be a char of 1x10 and my problem is that the matlab when it writes inside excel it puts like this the date
|A|B|C|D|E|F|G|H|I|J|K|L|
1 | | | | | | | | | | | | |
2 | | |2|0|1|6|-|1|1|-|1|5|
and I would like something like this
|A|B| C |D|
1 | | | | |
2 | | |2016-11-15| |
another problem I have is that the sheet where I place the info has already information in it for example, in excel.xlsx has the sheet "Test 1" already existing with information in the A17:A50 and in the F17:I17 and I am placing some information in the matrix C17:E[] with a matrix that is going to be [A,Area,Concentration] that are defined inside matlab so I put it
xlswrite(['Path\excel.xlsx'],horzcat(A, Area, Concentration), Test,'C17');
my problem is that the matlab erase the info that is already in the sheet even if it doesn’t write things in it (so all the cells in A17:A50 and in the F17:I17 after running the program will be empty). it is possible to say to matlab to "don’t touch" the cells that it doesn’t has to write? thanks
0 个评论
回答(1 个)
KSSV
2016-11-18
clc; clear all ;
close all;
pathname=fullfile(uigetdir());
dirdata = dir(fullfile(pathname,'.'));
dirdata= dirdata(arrayfun(@(x) x.name(1), dirdata) ~= '.');
fnsz = size(dirdata);
numfiles = fnsz(1);
filenames = cell(numfiles-1,1) ;
for n=1:numfiles-1
fullfilename=fullfile(pathname,dirdata(n).name);
name=regexp(char(dirdata(n).name),'\.','split');
fileID=name{1,1};
filenames{n}=fileID;
end
[savefile,savepath]=uiputfile('*.xlsx', 'Save results in an Excel file');
outname=fullfile(savepath,savefile);
if ispc
xlswrite(outname,filenames,'Sheet1','A1');
else
xlswrite(outname,filenames,'Sheet1','A1');
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!