Domanda

Ive saved a figure as a .fig-file in MATLAB which I did now reopen after some time.

Is there a way to access the data which is saved in the Histogram? I want to replot it by using the hist() command instead of imhist into a new figure (the reason is that matlab2tikz cant export the histogram plotted by imhist properly).

I imagine I could access the data when I would know the handle of the histogram, right?

EDIT:

A = findall(gcf,'type','axes');

then inspecting

get(A(i))

to see which axes the histogram is plotted in. This works but I have to figure out how to retrieve the actual data. But I somehow assume that I have to look at a parent/children of the axes handle (depending which hierarchy MATLAB creates of objects).

È stato utile?

Soluzione

Okay I figured it out finally. As written in my edit above, you can use findall to find the handles of all axes-objects. After using it, try to find out which handle refers to which axes by looking at the entries like X/YLim in get(A(i)), after finding the axes-ID and storing it (the k-th element in A) to idx = A(K), use this script to read the entries from the histogram plotted by imhist() -> The values are replicated as often as described by the bins (YData) and then replotted by hist into a new figure:

% ----------------------------------------------------------------------- %
b = get(idx);
b = get(b.Children); % Get the Plot-Handle
x = b.XData; % Bins
y = b.YData; % Bin-Counts

data = [];
for i = 1:length(x)
    data = [data x(i)*ones(1,y(i))]; % replicate data
end

figure
hist(data, length(unique(x)));
xlim([min(data) max(data)]);

Edit: The for-loop is a quick and dirty one ;-) Im sure there's a nicer solution e.g. by using repmat, but I was only interested in a quick solution :-)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top