Outputting Data in Excel

조회 수: 4 (최근 30일)
Alex
Alex 2012년 2월 14일
편집: Matt J 2013년 10월 12일
Hey all, I'm running the piece of code here:
data = csvread('data.csv');
assert (mod(size(data, 1), 3) == 0, ...
'Input data must have an integer multiple of 3 rows');
assert (size(data, 2) == 6, ...
'Input data must have exactly six columns.');
nsys = size(data, 1) / 3;
soln = zeros(nsys, 3);
options=optimset('MaxFunEvals',1e10,'MaxIter',25000);
for k = 1 : nsys,
F = generate_system(data(3*(k-1) + (1:3), 1:end));
guess = [1.55 0 300];
soln(k, :) = fsolve(F, guess,options);
end
fid=fopen('results.csv','a');
fprintf(fid,'%5.5f %5.5f %4.0f\n',soln);
fclose(fid);
It's purpose is to take a bunch of data, processes it through an fsolve command, and then output the three solutions. My problem right now is that the program outputs the data as the calculated array in a single cell, ie [20 0 300] appears in a single cell. It really is a nightmare for running further calculations. Does anyone know how to output the data in excel such that each peice of data occupies its own cell?
Thanks.

채택된 답변

Luca Tentoni
Luca Tentoni 2012년 2월 14일
Write your results using the xlswrite function. Simply write:
xlswrite('results.xls',soln);
See the xlswrite help page for further details.

추가 답변 (1개)

Eric
Eric 2012년 2월 14일
I think maybe you're missing the commas in
fprintf(fid,'%5.5f, %5.5f, %4.0f\n',soln);
Excel is viewing a CSV file as a comma-separated values text file. Without those commas, everything will appear in a single cell.
-Eric
  댓글 수: 1
Benjamin Schwabe
Benjamin Schwabe 2012년 2월 14일
The import wizard allows to you to use blank space as a separator as well. As there are several variations of formats depending on the language you are using Excel, I prefer Luca's approach: xlswrite.
- Ben

댓글을 달려면 로그인하십시오.

카테고리

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