How to write to CSV file

2 visualizzazioni (ultimi 30 giorni)
Mekala balaji
Mekala balaji il 14 Mar 2018
Risposto: Walter Roberson il 14 Mar 2018
Hi,
I have below cell array matrix, and I want to write to csv file in specified folder, with specified name
OuputFilePath: D:\outputData
OuputFileName: OutSuggestion
OutputData:
ParameterName ParameterValue
Gas_Flow.Sugg 0.23
Temperature.Upper 12.3
VSA.Flow.Pressure 0.72

Risposte (1)

Walter Roberson
Walter Roberson il 14 Mar 2018
OutputFilePath = 'D:\outputData';
OutputFileName = 'OutSuggestion.csv';
filename = fullfile(OutputFilePath, OutputFileName);
[fid, msg] = fopen(filename, 'wt');
if fid < 0
error('Could not open file "%s" because "%s"', fid, msg);
end
fprintf(fid, '%s,%s\n', OutputData{1,1}, OutputData{1,2});
temp = OutputData(2:end, :).'; %transpose is important
fprintf(fid, '%s,%f\n', temp{:});
fclose(fid);

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by