How to extract data from multiple Matlab figures
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Safi ullah
el 4 de Dic. de 2017
Comentada: Safi ullah
el 5 de Dic. de 2017
Hello everyone, I have extracted data from Matlab figure saved in “.fig” format by using the following code
open F1.fig %%F1.fig is the first figure
D = get(gca, 'children')
x=get(D, 'xdata');
y=get(D,'ydata');
z=get(D,'cdata');
x, y, and z are the extracted data of x,y and z components.For only one case I have total 90 figures so by using the above code for each figure take much time. Now I need to use the above code for all 90 figures and get the data at once. I tried by using for loop but it does not work. Thanks
0 comentarios
Respuesta aceptada
Walter Roberson
el 4 de Dic. de 2017
Editada: Walter Roberson
el 4 de Dic. de 2017
dinfo = dir('*.fig')
fignames = {dinfo.name};
numfig = length(fignames);
x = cell(numfig, 1);
y = cell(numfig, 1);
z = cell(numfig, 1);
for K = 1 : numfig
figfile = fignames{K};
try
fig = openfig(figfile);
ax = get(fig, 'CurrentAxes');
if ~isempty(ax)
D = get(ax, 'Children');
x{K} = get(D, 'XData');
y{K} = get(D, 'YData');
z{K} = get(D, 'ZData');
else
fprintf('note: file "%s" has empty current axes\n', figfile);
end
close(fig);
catch ME
fprintf('note: file "%s" could not be opened as figure\n', figfile);
end
end
5 comentarios
Walter Roberson
el 5 de Dic. de 2017
That is what my code already does. It creates cell arrays, x, y, and z, each of which has one entry per figure. For figures in which there was only one axes child, the entry will be a numeric vector. For figures in which there was more than one axes child, the entry will be a cell array of numeric vectors, one entry per child.
You have a number of figures, and each figure has an unknown number of axes children, so you nested structures are to be expected.
Más respuestas (0)
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!