Last active
September 14, 2017 12:27
-
-
Save tomsherborne/9a41cd9b9f202e07f03c42d85eef5dd7 to your computer and use it in GitHub Desktop.
Pulling data from a Matlab plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h = findobj(gca,'Type','Line'); | |
xd = get(h,'XData'); | |
yd = get(h,'YData'); | |
if iscell(xd) && iscell(yd) % Multi plot object | |
exprt = NaN*ones(length(yd{1}),length(yd)+1); | |
exprt(:,1) = xd{1}; | |
for i = 1:length(yd) | |
exprt(:,i+1) = yd{i}; | |
end | |
else % Single plot object | |
exprt = NaN*ones(length(yd),2); | |
exprt(:,1) = xd; | |
exprt(:,2) = yd; | |
end | |
dlmwrite('~/figdata.txt',exprt,'precision',6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Primitive data extraction routine for retrieving a comma delimited .txt file of a MATLAB
Useful for pulling data from MATLAB for PGFplot or other LaTeX rendering packages
Works with plot(), semilogx(), semilogy() and other Cartesian format figures on at least R2015a, 2015b, 2016a
Usage
Interpreting the output
plot(*x*,y)
Example:
will be formatted as: