Extracting x,y data from a folder of figures

I currently have code which extracts the x,y data from a set of figues into a cell of arrays of the data. This is what i want to have happen however there are two problems. One is that the code requires the figue to flash up and be closed to get the data. I tired to use the load function but had no luck. The other problem is that i currently pick the figures i want data from by making sure they end with the same letters. I ideally would like it so that the code starts with something like 'figures=uigetdir('C:\user\......') where i could navigate to a folder containing all the .fig files i want and load them.
Any help would be appreciated.
dinfo = dir('*mono.fig');
fignames = {dinfo.name};
numfig = length(fignames);
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)
hline = get(ax, 'Children');
y{K} = get(hline,'XData');
z{K} = get(hline,'YData');
end
close(fig);
end
end

 Risposta accettata

You can set the visibilty to off when loading the figure:
fig = openfig(figfile,'invisible');
That should take care of the flashing.
And what is your problem using uigetdir? The result will either be emtpy (in case the user closes the picker), or will contain a path you can use as input to dir (don't forget to add '*.fig').

4 Commenti

the invisible part works perfect but i tired changing the start to
data = uigetdir
dinfo = dir(data);
Which works however it now makes the first two cells in y and z both empty which makes the rest of the code not work.
Rik
Rik il 10 Ago 2021
Modificato: Rik il 10 Ago 2021
Of course that doesn't work. You forgot the semicolon so you could even see the content of data: only the folder. That is why I put the reminder in my answer.
data = uigetdir;
dinfo = dir(fullfile(data,'*.fig'));
The rest of your code assumes that every element in the struct returned by dir contains a figure with enough content to get the try-block work. However, you never confirm this is the case.
Ahh i understand now. Thank you very much
No problem, you're welcome.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Richiesto:

il 10 Ago 2021

Commentato:

Rik
il 10 Ago 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by