Error with transpose/permute

3 views (last 30 days)
Iugo on 2 Oct 2020
Commented: Iugo on 3 Oct 2020
Hello everyone!! I have this doubt about the use of permute. I have here a simulated hemodynamic response (simulating an task evoked fMRI) and I applied to these response a certain delay/lag. After this, I want to apply glmfit function to this hemodynamic response with the applied lag (my X) and to a 4D matrix (my Y), with this matrix simulating data from an fMRI. I didnt put the fMRI data here because you needed to download, so I used this matrix to simulate that data and to try to figure it out what´s going on. Basically the error is the following ""Error using ' Transpose on ND array is not defined. Use PERMUTE instead.", and I'm not even using the transpose function...
Please help me!!
Thank you so much for your time!
% import fMRI data (you can find this file on the internet)
data = load('P05120.7-MC.mat');
%expected hemodynamic response
% find our delay (lag) through cross-covariance
voxel = data.Vfunc(27,37,9,:);
new_voxel = reshape(voxel, [], 1);
[c lag] = xcov(new_voxel, hemo, 'coeff');
%applying lag to our hemodynamic response
delay = 0;
for z=1:length(c)
[max_cov, idx] = max(c);
if idx == z
delay = lag(z);
if delay > 0
hemo_lag = [(padarray(hemo(1:length(delay)-1),[delay,0],0, 'pre')); hemo(1: length(hemo)-delay)]; %aplicar lag à resposta hemodinamica
% applying glmfit function to every elements of the matrix
matriz = randn(2, 3,3,2);
m = permute(matriz,[2,1,3,4]);
for i=1:3
for j=1:2
for k=1:3
[params, dev, stats] = glmfit(hemo_lag(:), m(i,j,k,:), 'normal');
Iugo on 2 Oct 2020
Hi Rik! The full error message is this: Error using '
Transpose on ND array is not defined. Use PERMUTE instead.
Error in statslib.internal.removenan (line 38)
y = y';
Error in internal.stats.removenan (line 30)
[badin,wasnan,varargout{1:varargoutsize}] = statslib.internal.removenan(varargin{:});
Error in statremovenan (line 7)
[badin,wasnan,varargout{1:nargout-2}] = internal.stats.removenan(varargin{:});
Error in glmfit (line 190)
[anybad,wasnan,y,x,offset,pwts,N] = statremovenan(y,x,offset,pwts,N);
Error in project18_4 (line 36)
[params, dev, stats] = glmfit(hemo_lag(:), m(i,j,k,:), 'normal');

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 2 Oct 2020
In most cases, y is an n-by-1 vector of observed responses. For the binomial distribution, y can be a binary vector indicating success or failure at each observation, or a two column matrix with the first column indicating the number of successes for each observation and the second column indicating the number of trials for each observation.
matriz = randn(2, 3,3,2);
m = permute(matriz,[2,1,3,4]);
Those are 4 dimensional.
[params, dev, stats] = glmfit(hemo_lag(:), m(i,j,k,:), 'normal');
i, j, k are scalars, so m(i,j,k,:) is 1 x 1 x 1 x 2 . Something that is 1 x 1 x 1 x 2 is not an n x 1 vector or a array with two columns.
I suggest
Iugo on 3 Oct 2020
So what do you suggest? I'm not quite understanding what to do...

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!