forked from jooh/matlab-plotting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp2str.m
More file actions
35 lines (30 loc) · 812 Bytes
/
p2str.m
File metadata and controls
35 lines (30 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
% given a scalar or vector of p values, return a cell array of strings with
% n decimal places (default 3), where p values less than n are rounded to
% 10^-n.
%
% if doprefix is true, we prepend 'p=' for each string, except for values
% beyond the display range (p<10^-n) which get 'p<'.
%
% pstr = p2str(p,n,doprefix)
function pstr = p2str(pvec,n,doprefix)
if ieNotDefined('n')
n = 3;
end
if ieNotDefined('doprefix')
doprefix = false;
end
if doprefix
prefix = 'p=';
else
prefix = '';
end
pstr = arrayfun(@(p)sprintf(['%s%.' int2str(n) 'f'],prefix,max([p 10^-n])),pvec,...
'uniformoutput',false);
% hilarious Matlab behaviour - enter NaN, get .001...
pstr(isnan(pvec)) = {''};
if doprefix
smallind = pvec < 10^-n;
for n = find(smallind(:))'
pstr{n}(2) = '<';
end
end