How do I create a CSV with 2 columns and headers
35 次查看(过去 30 天)
显示 更早的评论
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 个评论
sloppydisk
2018-5-11
Have you checked out the documentation?
doc csvwrite
should show you how to do it.
采纳的回答
Image Analyst
2018-5-11
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 个评论
Image Analyst
2018-5-12
Then maybe you can unaccept your answer that doesn't work, and "Accept this Answer" or at least vote for it.
更多回答(1 个)
Rae Pond
2018-5-11
2 个评论
sloppydisk
2018-5-11
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.
Image Analyst
2018-5-12
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!