How do I create a CSV with 2 columns and headers

Greetings, I am stuck and can sure use some guidance. I have calculated the mean (mean2) and a standard deviation (std2) of a binary image. I am not sure how to create a CSV file that has 2 column headings for each result (mean and std). I have been playing around with these combinations: m=mean2(plant); s=std2(plant); csv('results.csv',m,s); or csv('results.csv',(m,s));

댓글 수: 1

Have you checked out the documentation?
doc csvwrite
should show you how to do it.

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

 채택된 답변

Image Analyst
Image Analyst 2018년 5월 11일

3 개 추천

Try using fprintf():
% Create random sample data for testing.
numImages = 10; % Whatever
means = 255 * rand(numImages, 2);
stdDevs = 10 * rand(numImages, 2);
fileName = fullfile(pwd, 'Results.csv');
fid = fopen(fileName, 'wt');
% Write headers
fprintf(fid, 'Mean, Standard Deviation\n');
% Write data.
fprintf(fid, '%f, %f\n', means, stdDevs);
fclose(fid);
% Type file to command window:
type(fileName)

댓글 수: 2

WOW! Thank you it's exactly what I was looking for
Then maybe you can unaccept your answer that doesn't work, and "Accept this Answer" or at least vote for it.

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

추가 답변 (1개)

Rae Pond
Rae Pond 2018년 5월 11일

0 개 추천

Hello- I looked at the doc csvwrite and redid my code but the values are listed in a single column below one another. Am I missing where it says in the text how to create two separate columns with headings? Thank you
m= mean2(newplant); %value 0.0300
s= std2(newplant); %value 0.1706
i=[m;s];0.1706
csvwrite('test.csv',i)

댓글 수: 2

If you write
i=[m;s]
you concatenate the columns downwards.
Instead you should put them next to each other like this:
i=[m s]
This will give you the desired result.
It will not because it will not "create a CSV file that has 2 column headings" as the poster requested and like the code in my answer does. This answer gives only numbers.

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

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

제품

릴리스

R2016b

질문:

2018년 5월 11일

댓글:

2018년 5월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by