User Tools

Site Tools


matlab:matlab_helpful_hacks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
matlab:matlab_helpful_hacks [2015/08/11 15:32] igorkaganmatlab:matlab_helpful_hacks [2018/11/01 06:03] igorkagan
Line 12: Line 12:
 ==== startup.m ==== ==== startup.m ====
  
-When MATLAB starts, it looks for a pathdef.m file in its startup directory.+When MATLAB starts, it will look for a **pathdef.m** file in its startup directory.
  
-Start up folder (in the icon | Properties | Start in ) (e.g. D:\Sources\MATLAB) allows controlling different paths and other settings via startup.m file placed in the folder, e.g.: +Start up folder (in the MATLAB icon | Properties | Start in ) (e.g. D:\Sources\MATLAB) allows controlling different paths and other settings via startup.m file placed in the folder, e.g.: 
  
 <code matlab> <code matlab>
 disp('Welcome to physiology analysis...'); disp('Welcome to physiology analysis...');
 set_sources_path; % set additional paths dynamically, e.g.  set_sources_path; % set additional paths dynamically, e.g. 
-p = genpath('D:\Sources\MATLAB'); addpath(p);+addpath(genpath('D:\Sources\MATLAB'));
  
 cd('F:\Data'); cd('F:\Data');
Line 28: Line 28:
 </code> </code>
  
 +==== Exiting loop (for / while -> pause) gracefully ====
 +(i.e., without "ctrl-C" abort)
 +
 +For example, when paging thru trials:
 +<code matlab>
 +figure('Name','Plot trial','CurrentChar',' ');
 +for k = 1:length(trial),
 +...
 + drawnow; pause;
 + if get(gcf,'CurrentChar')=='q', % pressing "q" will exist the loop, make sure focus is on the figure!
 + break;
 + end
 + clf;
 +end
 +</code>
 +
 +
 +==== Finding indices between two vectors of start and end indices, using arrayfun ====
 +
 +Assume we have two vectors, repeated_segments_start_idx, and repeated_segments_end_idx, and we want to find all indices between each pair. 
 +
 +<code matlab>
 +idx = [repeated_segments_start_idx(segments2remove_idx):repeated_segments_end_idx(segments2remove_idx)] % DOES NOT WORK, OF COURSE!
 +
 +idx = cell2mat(arrayfun(@colon,repeated_segments_start_idx,repeated_segments_end_idx,'UniformOutput',false)); % WORKS!
 +
 +</code>
 +
 +
 +==== Maximize figure window ====
 +<code matlab>set(gcf,'units','normalized','outerposition',[0 0 1 1]);</code>
 +
 +
 +
 +==== Plot an ''imagesc'' with transparent NaNs ====
 +
 +<code matlab>
 +h = imagesc(X,Y,C);
 +set(h,'alphadata',~isnan(C));
 +</code>
 +
 +
 +==== Shifting colormaps ====
 +Sometimes the colormap plots are shifted after printing. To fix this:
 +- in Adobe Illustrator, click on the colormap, release clipping mask, and go to "Object", "Rasterize", in the "Resolution" part click on the "Use Document Raster Effects Resolution".
 +
 +You have to do it for each of the colormaps.
  
  
  
matlab/matlab_helpful_hacks.txt · Last modified: 2022/12/29 07:15 by 127.0.0.1