Home > data-vis > visualize_cevent_patterns.m

visualize_cevent_patterns

PURPOSE ^

This is a plotting function for visualizing temperol pattens

SYNOPSIS ^

function visualize_cevent_patterns(data, args, cont_data, cont_args)

DESCRIPTION ^

 This is a plotting function for visualizing temperol pattens
 For input format, please see the function get_test_data() below
 
 Example:
 >>>  args.legend = {'Event1'; 'Event2'; 'Event3'; 'Event4'};
 >>>  plot_temp_patterns({}, 1, args)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function visualize_cevent_patterns(data, args, cont_data, cont_args)
0002 % This is a plotting function for visualizing temperol pattens
0003 % For input format, please see the function get_test_data() below
0004 %
0005 % Example:
0006 % >>>  args.legend = {'Event1'; 'Event2'; 'Event3'; 'Event4'};
0007 % >>>  plot_temp_patterns({}, 1, args)
0008 
0009 % add other vs target
0010 
0011 % debugging:
0012 % visualize_cevent_patterns(data, args)
0013 
0014 LENGTH_CEVENT = 3;
0015 text_unit = 0.35;
0016 text_offset = 2.6;
0017 
0018 if isempty(data)
0019     data = get_test_data();
0020 end
0021 
0022 if isfield(args, 'trial_times')
0023     max_trial_due = max(args.trial_times(:,2)-args.trial_times(:,1));
0024     text_unit = text_unit * (max_trial_due/100);
0025     text_offset = text_offset * (max_trial_due/100);
0026 end
0027 
0028 if ~exist('args', 'var')
0029     args.info = 'No user input information here';
0030 end
0031 
0032 % How many instances on each figure
0033 if isfield(args, 'MAX_ROWS')
0034     MAX_ROWS = args.MAX_ROWS;
0035 else
0036     MAX_ROWS = 20;
0037 end
0038 
0039 if isfield(args, 'colormap')
0040     colormap = args.colormap;
0041 else
0042     colormap = get_colormap();
0043 end
0044 
0045 % preprocess cell data, transfer it into a matrix
0046 if iscell(data)
0047     num_data_stream = size(data, 2);
0048     data_new = {};
0049     max_num_cvent_data_column = nan(1,num_data_stream);
0050     
0051     % go through each stream (each column in the cell data)
0052     for dsidx = 1:num_data_stream
0053         data_column = data(:,dsidx);
0054         
0055         data_column_length = cellfun(@(data_one) ...
0056             size(data_one, 1), ...
0057             data_column, ...
0058             'UniformOutput', false);
0059         data_column_length = vertcat(data_column_length{:});
0060         list_cevent_length = unique(data_column_length(:,1));
0061         % if data is a cell and needs to be processed
0062         if sum(~ismember(list_cevent_length, 1)) > 0
0063             max_data_column_length = max(list_cevent_length);
0064             data_column_new = nan(length(data_column), max_data_column_length*LENGTH_CEVENT);
0065             for didx = 1:length(data_column)
0066                 data_column_one = data_column{didx};
0067                 for doidx = 1:max_data_column_length
0068                     if doidx <= size(data_column_one,1)
0069                         data_column_new(didx,(doidx-1)*3+1:doidx*3) = ...
0070                             data_column_one(doidx,1:3);
0071                     end
0072                 end
0073             end
0074         else
0075             data_column_new = vertcat(data_column{:});
0076             max_data_column_length = list_cevent_length(1);
0077         end
0078         data_new{dsidx} = data_column_new;
0079         max_num_cvent_data_column(dsidx) = max_data_column_length;
0080     end
0081     data = horzcat(data_new{:});
0082     tmp_count = 0;
0083     for tmpi = 1:length(max_num_cvent_data_column)
0084         prev_tmp_count = tmp_count + 1;
0085         tmp_count = tmp_count + max_num_cvent_data_column(tmpi);
0086         stream_position_new(prev_tmp_count:tmp_count) = ...
0087             tmpi;
0088     end
0089     args.stream_position = stream_position_new;
0090 end
0091 
0092 % end
0093 [rows, cols] = size(data);
0094 if ~iscell(data)
0095     cols = cols / LENGTH_CEVENT;
0096 end
0097 
0098 if ~isfield(args, 'stream_position')
0099     args.stream_position = ones(1,cols);
0100 end
0101 
0102 if isfield(args, 'legend')
0103     if ~isfield(args, 'legend_location')
0104         if ~exist('cont_args', 'var')
0105             args.legend_location = 'NorthEastOutside';
0106         else
0107             args.legend_location = 'NorthWestOutside';
0108         end
0109     end
0110 end
0111 
0112 if isfield(args, 'ForceZero')
0113     if isfield(args, 'ref_index')
0114         ref_index = args.ref_index;
0115     elseif isfield(args, 'ref_column')
0116         ref_column = args.ref_column;
0117     else
0118         ref_column = 2;
0119     end
0120     
0121     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0122     if ~iscell(data)
0123         if isfield(args, 'time_ref')
0124             time_ref = args.time_ref;
0125         elseif exist('ref_column', 'var')
0126             time_ref = data(:,ref_column);
0127         else
0128             time_ref = data(ref_index(1), ref_index(2));
0129             time_ref = repmat(time_ref, size(data,1), 1);
0130         end
0131         
0132         tmp_ref_nan = sum(isnan(time_ref));
0133         if tmp_ref_nan > 0
0134             error('Error! There is nan data in the reference time column!');
0135         end
0136         data_mat = data;
0137     else
0138         data_mat = cell2mat(data);
0139         if isfield(args, 'time_ref')
0140             time_ref = args.time_ref;
0141         elseif exist('ref_column', 'var')
0142             time_ref = data(:,ref_column);
0143         else
0144             time_ref = data(ref_index(1), ref_index(2));
0145             time_ref = repmat(time_ref, size(data,1), 1);
0146         end
0147         if sum(isnan(time_ref)) > 0
0148 %             time_idx_list = sort([1:3:size(data_mat,2) 2:3:size(data_mat,2)]);
0149             nan_count_data = sum(isnan(data_mat));
0150             [I J] = find(nan_count_data);
0151             ref_column = min(setdiff(1:size(data_mat,2), J));
0152             if isfield(args, 'ref_column')
0153                 warning(['The reference column for ForceZero time has NaN ' ...
0154                     'values and thus is changd to column ' int2str(ref_column) '.']);
0155             end
0156             time_ref = data_mat(:,ref_column);
0157         end
0158     end
0159     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0160     
0161     for j = cols:-1:1
0162         data_mat(:,j*LENGTH_CEVENT-1) = data_mat(:,j*LENGTH_CEVENT-1) - time_ref;
0163         data_mat(:,j*LENGTH_CEVENT-2) = data_mat(:,j*LENGTH_CEVENT-2) - time_ref;
0164     end
0165 else
0166     data_mat = data;
0167 end
0168 
0169 if isfield(args, 'color_code') && strcmp(args.color_code, 'cevent_value')    
0170     value_idx_list = 3:LENGTH_CEVENT:size(data_mat,2);
0171     max_cevent_value = max(max(data_mat(:,value_idx_list)));
0172 end
0173 
0174 % to calculate how many figure will be needed in total
0175 num_figures = floor(rows/MAX_ROWS)+ceil(mod(rows/MAX_ROWS, 1));
0176 
0177 for fidx = 1:num_figures
0178     if isfield(args, 'figure_visible') && ~args.figure_visible
0179         h = figure('Visible','Off');
0180     else
0181         h = figure;
0182     end
0183     
0184     if isfield(args, 'set_position')
0185         set(h, 'Position', args.set_position);
0186     end
0187     
0188     if exist('cont_data', 'var')
0189         subplot(1,2,1);
0190         
0191         if ~exist('cont_args', 'var')
0192             cont_args.info = 'No user input information here';
0193         end
0194         
0195         cont_args.stream_position = args.stream_position;
0196         
0197         if ~isfield(cont_args, 'colormap')
0198             cont_args.colormap = {};
0199         end
0200         
0201         if ~isfield(cont_args, 'LineWidth')
0202             cont_args.LineWidth = 1;
0203         end        
0204         
0205         if isfield(cont_args, 'legend') && ~isfield(cont_args, 'legend_location')
0206             cont_args.legend_location = 'NorthEastOutside';
0207         end
0208     end
0209     %% The first half of the figure
0210     hold on;
0211     
0212     % to get how many rows/instances will be in this figure
0213     if fidx == num_figures
0214         if mod(rows, MAX_ROWS) == 0
0215             rows_one = MAX_ROWS;
0216         else
0217             rows_one = mod(rows, MAX_ROWS);
0218         end
0219     else
0220         rows_one = MAX_ROWS;
0221     end
0222     
0223     % to get the sub chunk of data for this figure
0224     if fidx == num_figures
0225         sub_data_mat = data_mat((fidx-1)*MAX_ROWS+1:end,:);
0226     else
0227         sub_data_mat = data_mat((fidx-1)*MAX_ROWS+1:(fidx)*MAX_ROWS,:);
0228     end
0229     
0230     start_time_idx = 1:LENGTH_CEVENT:size(sub_data_mat,2);
0231     end_time_idx = 2:LENGTH_CEVENT:size(sub_data_mat,2);
0232     
0233     min_x = nanmin(nanmin(sub_data_mat(:,start_time_idx))) - 0.1;
0234     max_x = nanmax(nanmax(sub_data_mat(:,end_time_idx))) + 0.1;
0235     max_y = 0;
0236     
0237     length_of_streams = length(unique(args.stream_position));
0238     each_stream_space = 1/length_of_streams;
0239     
0240     % draw legend cubics
0241     if isfield(args, 'legend') && isfield(args, 'colormap')
0242         for lidx = 1:length(args.legend)
0243             x = [min_x, min_x, min_x, min_x];
0244             y = [0.1, 1, 1, 0.1];
0245             color = args.colormap(lidx, :);
0246             fill(x, y, color);
0247         end
0248     end
0249 
0250     if isfield(args, 'row_text')
0251         row_text_pos_y = nan(MAX_ROWS, 1);
0252     end
0253     
0254     % Draw the background bars - white / grey
0255     for rowidx = 1:MAX_ROWS
0256         % Draw left to right in each row
0257         x = [min_x, max_x, max_x, min_x];
0258         y = [(rowidx-1)*(1+each_stream_space), (rowidx-1)*(1+each_stream_space), ...
0259             rowidx*(1+each_stream_space), rowidx*(1+each_stream_space)];
0260         color = [1 1 1];
0261 %         if mod(rowidx, 2) < 1
0262 %             color = [1 1 1];
0263 %         else
0264 %             color = [0.8 0.8 0.8];
0265 %         end
0266         fill(x, y, color);
0267     end
0268     
0269     % Draw actual instances row by row
0270     for rowidx = 1:rows_one
0271 %         min_y_row = 99;
0272 %         max_y_row = 0;
0273         % Draw left to right in each row
0274         pos_num_old = -1;
0275         for columnidx = 1:cols
0276             cevent_one = data_mat(rowidx+(fidx-1)*MAX_ROWS,(columnidx-1)*3+1:(columnidx-1)*3+3);
0277             pos_num_new = args.stream_position(columnidx);
0278             if isfield(args, 'var_text')
0279                 if iscell(args.var_text)
0280                     var_text_one =  args.var_text{pos_num_new};
0281                 elseif ischar(args.var_text)
0282                     var_text_one = sprintf('%s%d', args.var_text, pos_num_new);
0283                 end
0284             end
0285             
0286             if ~(isempty(cevent_one) || sum(isnan(cevent_one)) > 0)
0287                 start_time = cevent_one(1);
0288                 end_time = cevent_one(2);
0289 %                 if isfield(args, 'is_cont2cevent') && args.is_cont2cevent()
0290                 if cevent_one(3) > 100
0291                     cevent_one(3) = cevent_one(3) - args.cont_value_offset;
0292                     cont_colormap = get_colormap(args.cont_color_str{pos_num_new}, args.convert_max_int);
0293                     color = get_color(cevent_one(3), args.convert_max_int, cont_colormap);
0294                 else
0295                     if ~isfield(args, 'color_code') || strcmp(args.color_code, 'cevent_type')
0296                         color = get_color(columnidx, cols, colormap); %get_color(cevent_one(3));
0297                     elseif isfield(args, 'color_code') && strcmp(args.color_code, 'cevent_value')
0298                         color = get_color(cevent_one(3), max_cevent_value, colormap);
0299     %                     args.edge_color = get_color(mod(cevent_one(3), 10), max_cevent_value, colormap);
0300                     end
0301                 end
0302                 [~, y] = create_square(start_time, end_time, rowidx, columnidx, color, args);
0303                 y_new = mean(y);
0304                 if pos_num_old ~= pos_num_new && isfield(args, 'var_text')
0305                     text(-(text_unit*length(var_text_one)+text_offset), y_new, var_text_one, ...
0306                         'FontSize', 8, 'BackgroundColor', [0.8 0.8 0.8], 'Interpreter', 'none');
0307                 end
0308             elseif (cevent_one(3) == 0)
0309                 if pos_num_old ~= pos_num_new && isfield(args, 'var_text')
0310                     [~, y] = create_square(0, 0, rowidx, columnidx, [1 1 1], args);
0311                     y_new = mean(y);
0312                     text(-(text_unit*length(var_text_one)+text_offset), y_new, var_text_one, 'FontSize', ...
0313                         8, 'Color', [1 0 0], 'BackgroundColor', [0.8 0.8 0.8], 'Interpreter', 'none');
0314                 end
0315             else
0316                 if pos_num_old ~= pos_num_new && isfield(args, 'var_text')
0317                     [~, y] = create_square(0, 0, rowidx, columnidx, [1 1 1], args);
0318                     y_new = mean(y);
0319                     text(-(text_unit*length(var_text_one)+text_offset), y_new, var_text_one, 'FontSize', ...
0320                         8, 'Color', [1 1 1], 'BackgroundColor', [0.8 0.8 0.8], 'Interpreter', 'none');
0321                 end
0322             end
0323             pos_num_old = pos_num_new;
0324         end
0325         if isfield(args, 'row_text')
0326             row_text_pos_y(rowidx) = y(1);
0327         end
0328         max_y = rowidx*(1+each_stream_space);
0329     end
0330     
0331     % draw verticle lines according to the user
0332     if isfield(args, 'vert_line')
0333         for vidx = 1:length(args.vert_line)
0334             x = [args.vert_line(vidx), args.vert_line(vidx), args.vert_line(vidx)+0.01, args.vert_line(vidx)+0.01];
0335             y = [0, max_y, max_y, 0];
0336             color = [1 0 0];
0337             fill(x, y, 'r', 'EdgeColor', color);
0338         end
0339     end
0340 
0341     % set transpenrency, so the overlaps between cevents can be shown
0342     if isfield(args, 'transparency')
0343         alpha(args.transparency);
0344     end
0345     
0346     if isfield(args, 'legend')
0347         new_legend = cell(size(args.legend));
0348         for i = 1:length(args.legend)
0349             new_legend{i} = plot_no_underline(args.legend{i});
0350         end
0351         
0352         legend(new_legend, 'Location', args.legend_location);
0353     end
0354     
0355     if isfield(args, 'row_text')
0356         for rowidx = 1:rows_one
0357             if strcmp(args.row_text_type, 'time')
0358                 row_text_one = sprintf('%s: %.1f-%.1f', args.row_text{rowidx}, args.trial_times(rowidx, 1), args.trial_times(rowidx, 2));
0359             else
0360                 row_text_one = args.row_text{rowidx};
0361             end
0362             text(max_x+0.5, row_text_pos_y(rowidx), row_text_one, 'FontWeight', 'bold', 'Interpreter', 'none');%, 'FontSize', 12, 'BackgroundColor', [1 1 1]); -1*length(row_text_one)
0363         end
0364     end
0365     
0366     if isfield(args, 'xlim_list')
0367         xlim_list = args.xlim_list;
0368     else
0369         xlim_list = [min_x max_x];
0370     end
0371     
0372     if isfield(args, 'ylim_list')
0373         ylim_list = args.ylim_list;
0374     else
0375         ylim_list = [0 max_y];
0376     end
0377     
0378     xlim(xlim_list);
0379     ylim(ylim_list);
0380     
0381     if isfield(args, 'title')
0382         title(plot_no_underline(args.title), 'FontWeight', 'bold'); %, 'FontSize', 12, 'BackgroundColor', [1 1 1]
0383     end
0384     
0385     if isfield(args, 'xlabel')
0386         xlabel(args.xlabel);
0387     end
0388     
0389     %% the second half of the plot if applicable
0390     if exist('cont_data', 'var')
0391         subplot(1,2,2);
0392         hold on;
0393         
0394         % draw legend cubics
0395         if isfield(cont_args, 'legend') && isfield(cont_args, 'colormap')
0396             for lidx = 1:length(cont_args.legend)
0397                 color = get_color(lidx, length(cont_args.legend), colormap);
0398                 line([0], [0], 'Color', color);
0399             end
0400         end
0401         
0402         % to get the sub chunk of cont_data for this figure
0403         if fidx == num_figures
0404             sub_cont_data_mat = cont_data((fidx-1)*MAX_ROWS+1:end,:);
0405             sub_time_ref = time_ref((fidx-1)*MAX_ROWS+1:end,:);
0406         else
0407             sub_cont_data_mat = cont_data((fidx-1)*MAX_ROWS+1:(fidx)*MAX_ROWS,:);
0408             sub_time_ref = time_ref((fidx-1)*MAX_ROWS+1:(fidx)*MAX_ROWS,:);
0409         end
0410 
0411         min_x = 99;
0412         max_x = -99;        
0413         for rowidx = 1:rows_one
0414             vec = sub_cont_data_mat{rowidx,1};
0415             tmp_min_x = nanmin(vec(:,1) - sub_time_ref(rowidx));
0416             tmp_max_x = nanmax(vec(:,1) - sub_time_ref(rowidx));
0417             if tmp_min_x < min_x
0418                 min_x = tmp_min_x;
0419             end
0420             if tmp_max_x > max_x
0421                 max_x = tmp_max_x;
0422             end
0423         end
0424         min_x = min_x - 0.2;
0425         max_x = max_x + 0.2;
0426 
0427         % Draw the background bars - white / grey
0428         for rowidx = 1:MAX_ROWS
0429             % Draw left to right in each row
0430             x = [min_x, max_x, max_x, min_x];
0431             y = [(rowidx-1)*(1+each_stream_space), (rowidx-1)*(1+each_stream_space), ...
0432                 rowidx*(1+each_stream_space), rowidx*(1+each_stream_space)];
0433             if mod(rowidx, 2) < 1
0434                 color = [1 1 1];
0435             else
0436                 color = [0.8 0.8 0.8];
0437             end
0438             fill(x, y, color);
0439         end
0440         
0441         if isfield(cont_args, 'target_value_ref_column')
0442             target_value_ref_column = cont_args.target_value_ref_column;
0443             if mod(target_value_ref_column, LENGTH_CEVENT) ~= 0
0444                 error('Invalid target_value_ref_column value!');
0445             end                
0446 
0447             value_column = sub_data_mat(:,target_value_ref_column);
0448         end
0449         
0450         % start draw lines one by one
0451         for rowidx = 1:rows_one
0452             if isfield(cont_args, 'target_value_ref_column')
0453                 value_id = value_column(rowidx);                
0454                 vec = sub_cont_data_mat{rowidx,value_id};
0455                 
0456                 if ~isempty(cont_args.colormap)
0457                     color = cont_args.colormap{value_id};
0458                 else
0459                     color = get_color(value_id, size(sub_cont_data_mat, 2), colormap); %get_color(cevent_one(3));
0460                 end
0461                 
0462                 create_line(vec, rowidx, sub_time_ref(rowidx), color, cont_args);
0463             else
0464                 for cdmi = 1:size(sub_cont_data_mat, 2)                
0465                     if ~isempty(cont_args.colormap)
0466                         color = cont_args.colormap{cdmi};
0467                     else
0468                         color = get_color(cdmi, size(sub_cont_data_mat, 2), colormap); %get_color(cevent_one(3));
0469                     end
0470 
0471                     vec = sub_cont_data_mat{rowidx,cdmi};
0472                     create_line(vec, rowidx, sub_time_ref(rowidx), color, cont_args);
0473                 end
0474             end
0475         end
0476         
0477         % draw verticle lines according to the user
0478         if isfield(cont_args, 'vert_line')
0479             for vidx = 1:length(cont_args.vert_line)
0480                 x = [cont_args.vert_line(vidx), cont_args.vert_line(vidx), cont_args.vert_line(vidx)+0.01, cont_args.vert_line(vidx)+0.01];
0481                 y = [0, max_y, max_y, 0];
0482                 color = [1 1 1];
0483                 fill(x, y, 'k', 'EdgeColor', color);
0484             end
0485         end
0486 
0487         xlim([min_x max_x]);
0488         ylim([0 max_y]);
0489         
0490         if isfield(cont_args, 'legend')
0491             new_legend = cell(size(cont_args.legend));
0492             for i = 1:length(cont_args.legend)
0493                 new_legend{i} = plot_no_underline(cont_args.legend{i});
0494             end
0495             legend(new_legend, 'Location', cont_args.legend_location);
0496         end
0497 
0498         if isfield(cont_args, 'title')
0499             title(plot_no_underline(cont_args.title), 'FontSize', 14, 'FontWeight', 'bold');
0500         end
0501     end
0502     
0503     set(gca, 'ytick', []);
0504     hold off;
0505     %% all the plotting is done, start saving
0506     if isfield(args, 'save_name')
0507         save_name = args.save_name;
0508         
0509         fs = 8;
0510         paper = [0 0 15 8];
0511         
0512         h = gcf;
0513         set(h, 'PaperPositionMode', 'manual');
0514         set(h, 'PaperUnits', 'inches');
0515         set(h, 'InvertHardCopy', 'off');
0516         set(h, 'PaperPosition', paper);
0517         set(findall(h,'-property','FontSize'),'FontSize', fs)
0518         
0519         if isfield(args, 'save_multiwork_exp_dir')
0520             save_name = fullfile(args.save_multiwork_exp_dir, save_name);
0521         end
0522         if ~isfield(args, 'save_format')
0523             save_format = 'png';
0524         else
0525             save_format = args.save_format;
0526         end
0527     
0528         if isfield(args, 'figure_visible') && ~args.figure_visible
0529             saveas(h, [save_name '_' int2str(fidx) '.' save_format]);
0530         else
0531             if isfield(args, 'set_position')
0532                 set(gcf, 'Position', args.set_position);
0533                 pause(1)
0534             end
0535             if isfield(args, 'print') && args.print
0536                 print(h, [save_name '_' int2str(fidx) '.' save_format], '-dpng');
0537             else
0538                 ftmp = getframe(gcf);              %# Capture the current window
0539                 imwrite(ftmp.cdata, [save_name '_' int2str(fidx) '.' save_format]);  %# Save the frame data
0540             end
0541         end
0542 %         print(h, '-dpsc', [save_name '_' int2str(fidx) '.' save_format]);
0543         close(h);
0544         
0545     end
0546 end
0547 
0548 end
0549 
0550 % Get color according to rainbow color cue pallet
0551 function color = get_color(k, k_base, colormap)
0552     if ~isempty(colormap);
0553         color = colormap(k, :);
0554     else
0555         color = hsv2rgb([k/k_base,1,0.85]);
0556     end
0557 end
0558 
0559 % Draw one rectangle
0560 % x1: start time
0561 % x2: end time
0562 % y1: y axe coordinate (center)
0563 % color: color of the shape
0564 % height: the height of each rectangle, default value is 0.25
0565 function [x, y] = create_square(x1, x2, y1, cidx, color, args)          
0566     length_of_streams = length(unique(args.stream_position));
0567     each_stream_space = 1/length_of_streams;
0568     position_value = args.stream_position(cidx);
0569 %         color = color*(each_stream_space*position_value)+...
0570 %             (1-each_stream_space*position_value);
0571     y1 = (y1-1)*(1+each_stream_space);
0572     y1 = y1 + (length_of_streams-position_value+1)*each_stream_space;    
0573     
0574     if ~isfield(args, 'height')
0575         height = each_stream_space*0.5; %0.2;
0576     else
0577         height = args.height;
0578     end
0579     if isfield(args, 'edge_color')
0580         edge_color = args.edge_color; %0.2;
0581     else
0582         edge_color = 'none';
0583     end
0584     
0585     x = [x1, x2, x2, x1];
0586     y = [y1-height, y1-height, y1+height, y1+height];
0587     rect = fill(x, y, color, 'EdgeColor', edge_color);
0588 end
0589 
0590 %%%%%%%%%%%%%%%%%%%%%%%%%
0591 % create line
0592 %
0593 % vec: one chunk of cont data, [time data]
0594 % row: xth row this chunk at
0595 % time_ref: the 0 time spot / offset
0596 %
0597 function ln = create_line(vec, row, time_ref, color, args)
0598     length_of_streams = length(unique(args.stream_position));
0599     each_stream_space = 1/length_of_streams;
0600     
0601     x = vec(:,1) - time_ref;
0602     y = vec(:,2);
0603     max_y = nanmax(y);
0604     min_y = nanmin(y);
0605     alpha = (1+each_stream_space)/(max_y - min_y);
0606     y = (y - min_y)*alpha + (row-1)*(1+each_stream_space);
0607     ln = line(x, y, 'Color', color, 'LineWidth', args.LineWidth);
0608 end
0609 
0610 % Get test data
0611 function ret = get_test_data()
0612 
0613 ret = {
0614         [0.1 0.2 1], [0.3 0.43 2], [0.5 0.6 3], [0.36 0.7 4], [0.7 1.0 5];
0615         [0 0.3 1], [0.3 0.54 2], [0.5 0.6 3], [0.6 0.7 4], [0.7 1.0 5];
0616         [0.1 0.35 1], [0.3 0.5 2], [0.5 0.6 3], [0.6 0.7 4], [0.7 1.0 5];
0617         [0.1 0.2 1], [0.2 0.4 2], [0.5 0.6 3], [0.6 0.7 4], [0.7 1.0 5];
0618         [0 0.23 1], [0.3 0.4 2], [0.5 0.6 3], [0.6 0.7 4], [0.7 1.0 5];
0619         [0.13 0.21 1], [0.35 0.5 2], [0.5 0.65 3], [0.6 0.7 4], [0.7 1.0 5];
0620         [0.1 0.3 1], [0.3 0.4 2], [0.5 0.6 3], [0.6 0.79 4], [0.7 1.0 5];
0621         [0.1 0.32 1], [0.3 0.5 2], [0.5 0.6 3], [0.6 0.7 4], [0.7 1.0 5];
0622     };
0623 end

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005