profile on
<run your script here>
profile off
profile report[from Anand Venkataraman]
profile on
<run your script here>
profile off
profile reportdatvar to a file mydata.dat, all you have to do is say
save mydata.dat datvarHowever if you want to dynamically generate your filename, things get a little tricky since MATLAB's documentation is sparse about this. Here's how:
% Create a filename (myfile.001) using sprintf
fOut = sprintf('myfile.%03d',i); % say, i=1
% save data as an ASCII file
save(fOut, 'datvar', '-ascii');
% Or, create a mat file - (myfile001.mat)
% since MATLAB binary files typically have the extension .mat
fOut = sprintf('myfile%03d.mat',i); % say, i=1
% save data as matlab binary
save(fOut, 'datvar');
datvar is an array. Remember that the .mat file will retain the name of the variable datvar but the ASCII file will only contain data.
The idea is to create plot figures and compile them as frames of your movie.
% Create a new figure, and position it
fig1 = figure;
winsize = get(fig1,'Position');
winsize(1:2) = [0 0];
% Create movie file with required parameters
fps= 25;
outfile = sprintf('%s',outFileName)
mov = avifile(outfile,'fps',fps,'quality',100);
% Ensure each frame is of the same size
set(fig1,'NextPlot','replacechildren');
for i=1:numframes
plot(x,y); % generate your plot
% put this plot in a movieframe
% In case plot title and axes area are needed
% F = getframe(fig1,winsize);
% For clean plot without title and axes
F = getframe;
mov = addframe(mov,F);
end
% save movie
mov = close(mov);
Voila! (Make sure that you do not open any window over your plot window while MATLAB is compiling your movie, else those windows will become part of your movie)
Assume that your data is available in arraysarrData1andarrData2. Create an XML document node, sayNode1as follows:
docNode = com.mathworks.xml.XMLUtils.createDocument('Node1');
docRootNode = docNode.getDocumentElement;
Now put the data in the data nodes..
for i=1:length(arrData1),
% create nodes..
elPar = docNode.createElement('DataParent');
elData1 = docNode.createElement('Data1');
elData2 = docNode.createElement('Data2');
% put data in nodes..
elData1.appendChild(...
docNode.createTextNode(sprintf('%f', arrData1(i))));
elData2.appendChild(...
docNode.createTextNode(sprintf('%f', arrData2(i))));
% put nodes in the correct positions..
elParent.appendChild(elData1);
elParent.appendChild(elData2);
docRootNode.appendChild(elParent);
end
Now save the XML document. You can save it directly, or useuiputfileto get the standard save dialog of the OS.
[filename, pathname] = uiputfile(...
sprintf('%s.xml', datFile), 'Save XML file as');
% Save the XML document.
% xmlFileName = [dataOutFile,'.xml'];
xmlFileName = fullfile(pathname, filename);
xmlwrite(xmlFileName,docNode);
% open xml file to see your output
edit(xmlFileName);
To see more ways of using XML with MATLAB, refer to Java's documentation and play around to see what works.
This website was intended to be a little collection of tips and tricks, but I haven't been able to update it as often as I originally in...