How to export data from matlab to csv file from loop?
13 views (last 30 days)
Show older comments
Jessica Flores
on 30 Jun 2015
Answered: Walter Roberson
on 30 Jun 2015
I have a bunch of data from a for loop that I need to export from matlab to csv file. I tried csvwrite('test.xlsx',data). When I open up the csv file, the data for a single iteration comes up. How can I get the data from every iteration to export to the csv file?
if true
% code
end
fileFolder = fullfile(matlabroot, 'toolbox', 'images', 'imdata');
dirOutput = dir('/Users/JessFlores/Documents/MATLAB/XrayEye_*.tiff');
fileNames = {dirOutput.name}'
numFrames = numel(fileNames)
figure(); hold on
for p = 0001:numFrames
sequence(:,:,p) = imread(fileNames{p});
%intensity plot info
[x,y] = size(sequence(:,:,p));
X = 1:x;
Y = 1:y;
[xx,yy] = meshgrid(Y,X);
i = im2double(sequence(:,:,p));
%maz and FWHM x and y from plot
[mz,k] = max(i(:));
[ix,jy] = ind2sub(size(i),k);
[ix,jy,mz];
%max intensity coordinates in microns
%pixel size is 6.45x6.45 microns
ix = 6.45*ix;
jy = 6.45*jy;
[ix,jy,mz];
mhz = 0.5*mz;
[ihx,jhy]=ind2sub(size(i),k);
[ihx,jhy,mhz];
FWHMx = abs(ix-ihx)*2;
FWHMy = abs(jy-jhy)*2;
%table of data from plot
f = figure;
data = [ix,jy,mz,FWHMx,FWHMy];
colnames = {'X(Zmax) [um]', 'Y(Zmax) [um]', ...
'Zmax/Max Intensity', 'FWHMx [um]', 'FWHMy [um]'};
t = uitable(f, 'Data', data, 'ColumnName', colnames, 'ColumnWidth', {120});
t.Position(3) = t.Extent(3);
t.Position(4) = t.Extent(4);
%make subplot of table and intensity plot
subplot(2,1,1) = mesh(xx,yy,i); colorbar;
title('Intensity of Beam Image as a Function of Pixel Position');
xlabel('X(pixels)');
ylabel('Y (pixels)');
zlabel('Intensity (double precision corrected) [a.u.]');
csvwrite('test.csv', data);
end
hold off
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!