Calculations on a particular data dimension, from a structure with varying dimensions per field
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a structure of parameters (part of a texture synthesis program), which contains 10 fields, each has sets of parameters with different dimensionality.
textStruct =
pixelStats: [30x6 double]
pixelLPStats: [30x5x2 double]
autoCorrReal: [4-D double]
autoCorrMag: [5-D double]
magMeans: [30x18 double]
cousinMagCorr: [4-D double]
parentMagCorr: [4-D double]
cousinRealCorr: [4-D double]
parentRealCorr: [4-D double]
varianceHPR: [1x30 double]
This structure is a sample of 30 sets of texture parameters. I am trying to conduct tests of normality for the first dimension of each (i.e. across the 30 samples), so that every value in every field has a test within its own group of 30 values. This is achieved by some simple functions by including a value for dims(example with mean and std below). Here is the example of using mean(x,dim) and std(x,flag,dim), and zscore(x,dist,dim) that is computed after converting my structure into a matrix.
FN = fieldnames(textStruct)
for i = 1:length(FN)
fn = FN{i};
% THIS BIT CONVERTS TO MAT
% for each field, convert input cell arrays into one (N+1)-dim matrix
ss = {textStruct.(fn)}; %input cell array of data
ssdim = ndims(ss{1}); % dimensions of the data
TT = cell2mat(reshape(ss,[ones(1,ssdim),sz])); %convert to matrix of appropriate dims
% PERFORM CALCULATIONS
M.(fn) = mean(TT,ndims(TT)); %gets sample mean for each cell
S.(fn) = std(TT,0,ndims(TT)); % get sample stdev
Z.(fn) = zscore(TT,0,ndims(TT)); % get zscores
%%something here along the lines of kstest(TT,ndims(TT)) is what I need!
end
Without the in-built functionality of the dims command, I am struggling to access the chunks of data that I require. I am using kstest for normality, and need to send it vectors of 30 data points, representing each value in textStruct across the 30 samples. I have racked my brain and the best solution I can come up with is to explicitly create loops for each field with the required depth according the ndims(current_field). I have a gut feeling that there is a better way of accomplishing this without hardcoding anything, but am totally lost!
I hope I have described my problem sufficiently, thanks for taking a look.
Alex
댓글 수: 0
채택된 답변
Guillaume
2014년 9월 25일
I believe the following should work:
TTcell = num2cell(TT, ndims(TT)); %each cell is the elements of TT in the last dimension
TTktest = cell2mat(cellfun(@(v) ktest(squeeze(v)), TTcell, 'UniformOutput', false));
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!