User Tools

Site Tools



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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
matlab:matlab_helpful_hacks [2015/08/09 14:47]
igorkagan [startup.m]
matlab:matlab_helpful_hacks [2019/07/10 11:46] (current)
Line 10: Line 10:
 x = {1,​[],​[],​[]};​ find(~cellfun(@isempty,​x)) </​code>​ x = {1,​[],​[],​[]};​ find(~cellfun(@isempty,​x)) </​code>​
-==== startup.m ==== 
-Starting folder ​for MATLAB (in the icon | Properties | Start in ) (e.g. D:​\Sources\MATLABallows controlling different paths and other settings via startup.m file placed in the folder, e.g.: +==== Exiting loop (for / while -> pausegracefully ==== 
 +(i.e., without "​ctrl-C"​ abort)
 +For example, when paging thru trials:
 <code matlab> <code matlab>
-disp('Welcome to physiology analysis...'); +figure('Name','​Plot trial','​CurrentChar',' ​'); 
-set_sources_path+for k = 1:​length(trial),​ 
-cd('F:\Data'); +... 
-edit+ drawnowpause;  
-EditorMacro('Alt-Control-h', ​@createHeaderComment_dag);+ if get(gcf,'CurrentChar')=='​q',​ % pressing "​q"​ will exist the loop, make sure focus is on the figure! 
 + break
 + end 
 + clf
 +==== 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!
-dbstop if error 
 </​code>​ </​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);​
 +==== 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.1439131675.txt.gz · Last modified: 2015/08/09 14:47 by igorkagan