Editing CSV File Specifying Range for Mac User
Ältere Kommentare anzeigen
I'm wondering if anyone has been able to write to a csv file specifying a range to write to.
Xlswrite worked perfectly when I ran my program on windows, but it's a different story for mac.
I have been able to append to csv files using the following code:
function cell2csv(filename,cellArray,delimiter,mode)
% Writes cell array content into a *.csv file.
%
% CELL2CSV(filename,cellArray,delimiter)
%
% filename = Name of the file to save. [ i.e. 'text.csv' ]
% cellarray = Name of the Cell Array where the data is in
% delimiter = seperating sign, normally:',' (it's default)
% mode = specifies the mode of opening the file. See fopen() for a detailed
% list (default is overwrite i.e. 'w')
%
% by Sylvain Fiedler, KA, 2004
% modified by Rob Kohr, Rutgers, 2005 - changed to english and fixed delimiter
if nargin<3
delimiter = ',';
end
if nargin<4
mode = 'w';
end
datei = fopen(filename,mode);
for z=1:size(cellArray,1)
for s=1:size(cellArray,2)
var = eval(['cellArray{z,s}']);
if size(var,1) == 0
var = '';
end
if isnumeric(var) == 1
var = num2str(var);
end
fprintf(datei,var);
if s ~= size(cellArray,2)
fprintf(datei,[delimiter]);
end
end
fprintf(datei,'\n');
end
fclose(dabei);
------------
However I must update a certain column in my csv data.
I attempted using xlwrite but this code seems incompatible for csv files: http://www.mathworks.com/matlabcentral/fileexchange/38591-xlwrite--generate-xls-x--files-without-excel-on-mac-linux-win
Anyone know how i could possibly tweak this code or CELL2CSV to include a range to edit my csv file?
Thanks in advance
2 Kommentare
Walter Roberson
am 10 Feb. 2016
In MS Windows that has Excel installed, MATLAB uses ActiveX to talk to Excel to do xlsread() and xlswrite(), so MATLAB is able to access the full flexibility of Excel. If Excel is not installed or the operating system is not MS Windows then this path does not work, so MATLAB is restricted to some code that handles a subset of possibilities. One of the restrictions is that ranges cannot be specified.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!