Why am I getting a matrix when [I think] I should be getting a vector?
Ältere Kommentare anzeigen
The code below is meant to calculate the histogram in each 3D array of a 4D array. It spits out maxV as a matrix but I'm expecting it to be a vector (same size as minV). This only happens when I omit the variable 'distrib' from the list of output parameters. Why does minV come out as expected but not maxV?
The input can be a simple:
volume = rand(3,3,3,3); bins = 5;
[distrib, maxV, minV] = myFunction(volume, bins)
compare with
[maxV, minV] = myFunction(volume, bins)
This is the function code:
function [distrib, maxV, minV] = myFunction(volume, bins, minV, maxV)
% volume: 4th order tensor (example: a volume with >1 co-located attributes)
% bins: number of bins in the histogram
% minV: minimum value in the i-th tensor
% maxV: maximum value in the i-th tensor
clear minV maxV binEdge
n = size(volume,4); % check number of attributes
% if no minV input then find min values for each attribute
if ~exist('minV')
for i = 1:n
mV = min(min(min(volume(:,:,:,i))));
minV(i) = mV;
end
end
% if no maxV input then find max values for each attribute
if ~exist('maxV')
for i = 1:n
mV = max(max(max(volume(:,:,:,i))));
maxV(1,i) = mV
end
end
X = bins+1; % bins vector
distrib = zeros(X,n);
for i = 1:n
d = volume(:,:,:,i);
% set the EDGE vector for the i-th attribute (same number of bins each time)
binEdge = (minV(i)):((maxV(i)-minV(i))/bins):(maxV(i));
% calculate the histogram for each attribute
h = hist(d(:),binEdge);
% place each histogram vector into distrib matrix
distrib(1:X,i) = h;
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Image Segmentation and Analysis finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!