⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rri_getsubject_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 3 页
字号:
       set(findobj(h0,'tag','chkSubjConsistency'), 'value', 0);
       num_subj_init = 0;
       chksubj = 0;
    else
       chksubj = 1;
    end

    setappdata(h0,'chksubj',chksubj);
    setappdata(h0,'num_subj_init',num_subj_init);
    setappdata(h0,'StartDirectory',StartDirectory);
    setappdata(h0,'condition', condition);
    setappdata(h0,'selected_conditions', selected_conditions);
    setappdata(h0,'old_dir', old_dir);
    setappdata(h0,'subj_files_row_old', subj_files_row_old);
    setappdata(h0,'subj_files', subj_files);
    setappdata(h0,'selected_dir', old_dir);

    setappdata(h0,'frame_pos', ...
	get(findobj(gcf,'Tag','frameCondition'),'Position'));
    setappdata(h0,'imgfile_filter', ...
	get(findobj(gcf,'Tag','editImageFilter'),'String'));

    imgfile_height = 0.06;
    setappdata(h0,'imgfile_height', imgfile_height);

    setappdata(h0,'top_cond_idx', 1);
    setappdata(h0,'duplicate_img',0);

    imgfile1_hdls = [c_h1,c_h2,c_h3,c_h4];	% save handles for the 1st one
    setappdata(h0,'imgfile_hlist', imgfile1_hdls);

    imgfile_template = copyobj(imgfile1_hdls,h0);
    set(imgfile_template, 'visible', 'off');
    setappdata(h0,'imgfile_template', imgfile_template);
    setappdata(h0,'saved_map',{});		% init saved subj map list
    setappdata(h0,'grp_selected_dir',{});	% init

    if isempty(subj_files_row_old)
       ListDirectory(old_dir, 1, []);
    else
       ListDirectory(old_dir, 1, old_dir);
    end

    SetupSubjectImageMap(0,0);
    SetupConditionRows;
    SetupSlider;
    DisplayConditions(1);
    UpdateSlider;

    return;						% init


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   ListDirectory: List all the subdirectories under dir_name
%
%   I (dir_name) - name of the directory that will be listed.
%   I (exist_sub) - set to 0 if there is no subdirectory under dir_name.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function ListDirectory(dir_name, exist_sub, old_dir)

    if ~exist('old_dir','var')
       old_dir = [];
    end

    imgfile_filter = getappdata(gcf,'imgfile_filter');

    dir_struct = dir(dir_name);
    if isempty(dir_struct)
        % msg = 'ERROR: Directory not found!';
        msg1 = 'Cannot find directory "';
        msg2 = '", please enter full path.';
        msg = [msg1,dir_name,msg2];
        set(findobj(gcf,'Tag','MessageLine'),'String',msg);
        return;
    end

	% preserve old mouse pointer, and make current pointer as 'Busy'
	% it is useful to execute slow process
	%
    old_pointer = get(gcf,'Pointer');
    set(gcf,'Pointer','watch');

	% get directory list
	%
    dir_list = dir_struct(find([dir_struct.isdir] == 1));
    [sorted_dir_names, sorted_dir_index] = sortrows({dir_list.name}');

	% get file list
	%
    dir_struct = dir([dir_name, filesep, imgfile_filter]);

    if isempty(dir_struct)
        sorted_file_names = [];
    else
        file_list = dir_struct(find([dir_struct.isdir] == 0));
        [sorted_file_names, sorted_file_index] = sortrows({file_list.name}');
    end;

    if (exist_sub)
        set(findobj(gcf,'Tag','listDirs'),'String',sorted_dir_names,'Value',1);
        set(findobj(gcf,'Tag','editSelectedDir'),'String',dir_name);
    end

    setappdata(gcf, 'filtered_files', sorted_file_names);


    %  add init char unique check  -jimmy
    %
    chk_init = char(sorted_file_names);

    if ~isempty(chk_init)
       num_subj_init = getappdata(gcf,'num_subj_init');
       chksubj = getappdata(gcf,'chksubj');
       chk_init = lower(chk_init(:,1:num_subj_init));
       chk_init = unique(chk_init,'rows');

       if size(chk_init,1) == 1 & chksubj
          set(findobj(gcf,'Tag','chkSubjConsistency'),'enable','on','value',1);
       else
          set(findobj(gcf,'Tag','chkSubjConsistency'),'enable','off','value',0);
       end
    end


    if isempty(old_dir)				% called by add subject
       set(gcf,'Pointer',old_pointer);		% Put 'Arrow' pointer back
       return; 					% ListDirectory
    else					% called by edit subj

       [pn, fn]=fileparts(old_dir);

       dir_struct = dir(pn);
       dir_list = dir_struct(find([dir_struct.isdir] == 1));
       [sorted_dir_names, sorted_dir_index] = sortrows({dir_list.name}');

       [tmp, idx] = intersect(sorted_dir_names, fn);

       set(findobj(gcf,'Tag','listDirs'),'String',sorted_dir_names,'Value',idx);
       set(findobj(gcf,'Tag','editSelectedDir'),'String',pn);

    end

    set(gcf,'Pointer',old_pointer);		% Put 'Arrow' pointer back
    return; 					% ListDirectory


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   SetupSubjectImageMap: For each subject, setup row of mapping matrix
%
%   modify_saved_map: flag. If 1, modify; if 0 not modify saved_map
%
%   sample_idx: use saved_map(sample_idx) as sample of all other subjects
%		if user request to change all other subj sequence when one
%		of them (sample_idx) was changed. valid value should > 0.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function SetupSubjectImageMap(modify_saved_map,sample_idx)

    selected_condition = getappdata(gcf,'selected_conditions');
    cond_name = getappdata(gcf,'condition');
    condnum = length(cond_name);
    cond_name(find(selected_condition == 0)) = [];

    h1 = findobj(gcf,'Tag','listDirs');
    selected_dir_idx = get(h1,'user');

    if length(selected_dir_idx) > 1

        msg = 'For this action, please select one directory only.';
        set(findobj(gcf,'Tag','MessageLine'),'String',msg);
        return;

    end

    saved_map = getappdata(gcf,'saved_map');
    keep_saved_map = 0;

    % don't need to modify saved_map array
    %
    if(~modify_saved_map)

        % if saved_map{selected_dir_idx} is available, while modify saved_map is not
        % required, then save the data and return
        %
        if length(saved_map)>=selected_dir_idx & ~isempty(saved_map{selected_dir_idx})
            subj_files_row = saved_map{selected_dir_idx};
            setappdata(gcf,'subj_files_row',subj_files_row);
            setappdata(gcf,'cond_name', cond_name);
            return;
        end
    end

    num_subj_init = getappdata(gcf,'num_subj_init');
    subj_files = getappdata(gcf,'subj_files');

    is_same_name = 0;

    filtered_files = getappdata(gcf, 'filtered_files');	% list of imgfile name

    if(length(filtered_files) < condnum)	% don't have enough imgfile

%        padnum = ceil(condnum/length(filtered_files));

%        temp = [];
%        for i = 1:padnum
%           temp = [temp; filtered_files];
%        end
%        filtered_files = temp;

%        setappdata(gcf,'duplicate_img',1);

        for i=1:(condnum-length(filtered_files))
            filtered_files = [filtered_files; {''}];
        end

    end

    % check sample usability
    %
    sample_chk = 0;

    if sample_idx > 0
        tmp = char(saved_map{sample_idx});

        if ~isempty(tmp)
            sample_chk = 1;
        end
    end

    % if any subject has already been entered
    % or if the subject file is being swapped
    %
    if ~isempty(subj_files) | (sample_idx > 0 & sample_chk == 1)

        if sample_idx > 0
           sample = char(saved_map{sample_idx});
        else
           sample = char(subj_files(:, 1));
        end

        sample = cellstr(sample(:, num_subj_init+1:end));

        cursor = char(filtered_files);
        cursor = cellstr(cursor(:, num_subj_init+1:end));

        compare = ismember(lower(sample), lower(cursor));
        is_same_name = all(compare);

        % Matlab 5 does not have index feature for ismember function
        %
        % [compare,idx] = ismember(lower(sample), lower(cursor));
        %
        % all the code below is used to get the idx
        %

        if is_same_name

            x=lower(sample);
            y=lower(cursor);

            for i=1:length(x)
               [tmp,idx(i)] = intersect(y,x(i));
            end
        end

    end

    if is_same_name &  get(findobj(gcf,'Tag','chkSubjConsistency'),'value')

        cursor = char(filtered_files);

        if isempty(cursor)
            subj_files_row = filtered_files(1:condnum);
        else
            sample = cellstr(cursor);

            sample = char(sample([idx]));
            sample = sample(:, num_subj_init+1:end);

            cursor = cursor(1:size(sample,1), 1:num_subj_init);

            subj_files_row = cellstr([cursor, sample]);
        end

    else
        subj_files_row = filtered_files(1:condnum);
    end

    saved_map{selected_dir_idx} = subj_files_row;

    if modify_saved_map
       setappdata(gcf,'saved_map',saved_map);		% save subj map list
    end

    setappdata(gcf,'subj_files_row',subj_files_row);
    setappdata(gcf,'cond_name', cond_name);

    return; 						% SetupSubjectImageMap


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   SetupConditionRows: Initially lay out all rows for the selected
%	conditions and their corresponding image files. Position is
%	determined by the frame position.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function SetupConditionRows()

    frame_pos = getappdata(gcf,'frame_pos');
    imgfile_height = getappdata(gcf,'imgfile_height');

    rows = floor(frame_pos(4) / imgfile_height);

    imgfile_hdls = getappdata(gcf,'imgfile_hlist');
    imgfile_template = getappdata(gcf,'imgfile_template');

	% A row of vertical positions, at which
	% the 10 4-controls will be located.
	%
    top_pos = get(imgfile_hdls(1,2),'Position');
    v_pos = top_pos(2) - [0:rows-1] * imgfile_height;

    select_cbf = 'rri_getsubject_ui(''select_imagefile'');';

    nr = size(imgfile_hdls, 1);		% size(x,1) get # of rows. nr = 1 for the initial
    if (rows < nr)						% too many rows
        for i = rows+1:nr,
            delete(imgfile_hdls(i,:));
        end
        imgfile_hdls = imgfile_hdls(1:rows, :);
    else							% add new rows
        for i = nr + 1:rows
            new_c_hdls = copyobj(imgfile_template, gcf);
            imgfile_hdls = [imgfile_hdls; new_c_hdls'];		% stack imgfile_hdls
        end
    end

    v = 'Off';
    for i=1:rows

	% take out the handle list created above, and use it
	% in the following 'idx,name,colon,combo'.
	% those handles are valid, since they are all obtained
	% from function copyobj() above.
	%

        new_c_hdls = imgfile_hdls(i,:);

	% init each condition idx
	%
        pos = get(new_c_hdls(1),'Position'); pos(2) = v_pos(i)-0.01;
        set(new_c_hdls(1),'String','','Position',pos,'Visible',v,'UserData',i);

	% init each condition name
	%
        pos = get(new_c_hdls(2),'Position'); pos(2) = v_pos(i);
        set(new_c_hdls(2),'String','','Position',pos,'Visible',v,'UserData',i);

	% init each colon (:)
	%
        pos = get(new_c_hdls(3),'Position'); pos(2) = v_pos(i);
        set(new_c_hdls(3),'String',':','Position',pos,'Visible',v,'UserData',i);

	% init each image file combo box
	%
        pos = get(new_c_hdls(4),'Position'); pos(2) = v_pos(i);
        set(new_c_hdls(4),'String',' ','Position',pos,'Visible',v, ...
						'UserData',i,'Callback',select_cbf);
    end

    setappdata(gcf,'imgfile_hlist', imgfile_hdls);
    setappdata(gcf,'NumRows',rows);

    return;						% SetupConditionRows


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   SetupSlider: Draw a slider,
%	%and use full displayed image file rows
%	%to determine the slider position.
%	and use the frame to determine the slider position
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function SetupSlider()

    pos_frame = get(findobj(gcf,'Tag','frameCondition'),'Position');

    slider_hdl = findobj(gcf,'Tag','sliderCondition');
    pos = get(slider_hdl,'Position');
    pos(2) = pos_frame(2) + 0.003030303;
    pos(4) = pos_frame(4) - 0.006060606;
    set(slider_hdl,'Position', pos);

    return;						% SetupSlider


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   DisplayConditions: Display all the selected conditions and their
%	corresponding image files.
%
%   I (init_flag): 1 means called by initial routine
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function DisplayConditions(init_flag)

    subj_files_row_old = getappdata(gcf, 'subj_files_row_old');
    filtered_files = getappdata(gcf, 'filtered_files');
    subj_files_row = getappdata(gcf, 'subj_files_row');
    cond_name = getappdata(gcf, 'cond_name');

    if (init_flag & ~isempty(subj_files_row_old))	% called from init
        % more file in directory than what we needed
        %
        if length(subj_files_row_old) <= length(filtered_files)
            subj_files_row = subj_files_row_old;
            setappdata(gcf, 'subj_files_row', subj_files_row);
        % not enough file in directory
        %
        else
            subj_files_row = [];	% indicate error, because
					% image files is less than saved
            msg = 'ERROR: Some subject files have been removed.';
            set(findobj(gcf,'Tag','MessageLine'),'String',msg);
        end
    end

    top_cond_idx = getappdata(gcf,'top_cond_idx');
    imgfile_hdls = getappdata(gcf,'imgfile_hlist');
    rows = getappdata(gcf,'NumRows');

    last_row = 0;				% no row at the beginning
    cond_idx = top_cond_idx;			% start from top row. Here's 1

    for i = 1:rows
        c_hdls = imgfile_hdls(i,:);
        if cond_idx <= length(cond_name)	% only display to these many rows
            set(c_hdls(1),'String',sprintf('%d.',cond_idx),'Visible','on');
            set(c_hdls(2),'String',sprintf('%s',cond_name{cond_idx}), ...
			'Visible','on');
            set(c_hdls(3),'String',':','Visible','on');
            if ~isempty(subj_files_row)
                set(c_hdls(4),'String',subj_files_row{cond_idx},'Value', ...
					cond_idx,'Visible','on');
            else					% display empty combo box
		set(c_hdls(4),'String',' ','Value',1,'Visible','on');
            end
            cond_idx = cond_idx + 1;
            last_row = i;
        else
            set(c_hdls(1),'String','','Visible','off');
            set(c_hdls(2),'String','','Visible','off');
            set(c_hdls(3),'String','','Visible','off');
            set(c_hdls(4),'String',' ','Visible','off');
        end;
    end;

	%  display or hide the slider
	%
    if (top_cond_idx ~= 1) | (last_row == rows)
        slider_hdl = findobj(gcf,'Tag','sliderCondition');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -