vendredi 23 octobre 2015

MATLAB: export data from checkboxes created by a loop for from a pushbutton

After making a code which creates a window with a figure and some (ii) checkboxes loading some data (one data per checkbox), I would like to export them by a pushbutton only if the checkbox matching a set of data is ticked.

First, I have created (with the help of "il_raffa") a number of checkbox which does need to be flexible (ii: input of a loop for) which out of my code can be summarized in principle by something like that:

GUI window

N=500;
M=300;

handles.fig=figure('Units', 'Pixels','Position',[100 100 N M]);

handles.axes=axes('Units', 'Pixels','tag','axes_tag','Position',[25 25 N-200     M-50]);

for ii=1:4; %input exemple

   handles.check{ii}=uicontrol('style','checkbox','string', ...
      ['Display_file_' num2str(ii)],'tag',['c_b_' num2str(ii)], ...
      'position',[N-150 M/2-ii*20 100 25],'callback','plot_sel_cb(handles.axes)');
end

checkbox callback

function plot_sel_cb(ax_h)
cb_id=get(gcbo,'string')
cb_pos=get(gcbo,'position')
val=get(gcbo,'value')
path=get(gcbo,'userdata');
axes(ax_h)
hold on

if val

   x=1:10;
   y=[1:10].*cb_pos(2)/100;
   plot(x,y,'color,[rand(1) rand(1) rand(1)])
   legend(cb_id)

    set(h,'tag',cb_id)


else 
    delete(findobj('tag',cb_id))
end

From this code I would like to create a pushbutton which takes only the [x,y] from the ticked checkboxes to create for example a variable with all these data inside.

The second issue is, I haven't managed to create a legend to "plot(x,y,'color,[rand(1) rand(1) rand(1)])" which add the name "cb_id" when the checkbox matching the data is ticked.

HELP

Thanks




Aucun commentaire:

Enregistrer un commentaire