Commit 9a07a608 authored by mikec1's avatar mikec1
Browse files

Dimension fixes to the ve_trimstd function.

parent d5c8c58b
function out=ve_trimstd(data,percent)
function trim_std = ve_trimstd(data,ptrim,dim)
% if percent<1;
% disp('multiplying percent input by 100...');
% percent=percent*100;
% end
%
% npnts=length(data);
% nppnts=round(npnts*(percent/100)/2);
% srtdata=sort(data);
%
% %Windsorize...
% srtdata(1:nppnts)=srtdata(nppnts+1); %set to all the same?????
% srtdata(npnts-(nppnts+1):end)=srtdata(npnts-(nppnts+1)-1); %set to all the same?????
% out=std(srtdata);
%
% %out=std(srtdata(nppnts+1:npnts-(nppnts+1))); %result is all the same #
% Function based off of ve_trimmean
if percent >= 1;
percent = percent/100;
if dim > 2;
disp('ERROR: dim must be 1 or 2');
return
end
percent = percent/2;
if nargin < 3;
dim = 1;
end
if ptrim >= 1;
ptrim = ptrim/100;
end
ptrim = ptrim/2;
ntotal = length(data);
ntrim = round(ntotal*percent);
if dim==1;
ntotal = size(data,1);
else
ntotal = size(data,2);
end
data_srt = sort(data);
ntrim = round(ntotal*ptrim);
%Take 1/2 of the requested amount off the top and off the bottom
out = std(data_srt(ntrim+1:ntotal-ntrim));
%switch dim
% case 1
%
% for i=1:size(data,3);
%
% npnts=size(data,2);
% nppnts=round(npnts*(percent/100));
% srtdata=sort(data(:,:,i),2);
%
% out(:,:,i)=std(srtdata(nppnts+1:npnts-(nppnts+1),:),[],dim);
%
% end
%
% case 2
%
% for i=1:size(data,3);
% size(data(:,:,i))
%
% npnts=size(data,1);
% nppnts=round(npnts*(percent/100));
% srtdata=sort(data(:,:,i),1);
% size(srtdata)
% nppnts+1
% npnts-(nppnts+1)
% out(:,:,i)=std(srtdata(:,nppnts+1:npnts-(nppnts+1)),[],dim);
%
% end
%
%end
\ No newline at end of file
if dim==1;
data_srt = sort(data,1);
trim_std = std(data_srt(ntrim+1:ntotal-ntrim,1:size(data_srt,2)),0,1);
else
data_srt = sort(data,2);
trim_std = std(data_srt(1:size(data_srt,1),ntrim+1:ntotal-ntrim),0,2);
end
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment