Error with transpose/permute

4 views (last 30 days)
Iugo
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
hemo=[repmat(0,10,1);repmat(1,10,1);repmat(0,10,1);repmat(1,10,1);repmat(0,10,1);repmat(1,10,1);repmat(0,10,1);repmat(1,10,1);repmat(0,10,1);];
% 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);
end
if delay > 0
hemo_lag = [(padarray(hemo(1:length(delay)-1),[delay,0],0, 'pre')); hemo(1: length(hemo)-delay)]; %aplicar lag à resposta hemodinamica
end
end
% 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');
end
end
end
  2 Comments
Rik
Rik on 2 Oct 2020
What is the full error message? It is unclear which command in your code triggers the error.
Iugo
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
squeeze(m(i,j,k,:))
  5 Comments
Walter Roberson
Walter Roberson on 3 Oct 2020
Your code does not define hemo_lag . You assign to hemo_lag if delay > 0 but you assign 0 to delay so that assignment is never done. We have to presume that hemo_lag was loaded in with the file. The assignment you do hints strongly that hemo_lag is a lot larger than size(m,4), which is 2.
Your assignment to matriz should very likely have at least one dimension whose size depends upon the number of elements in hemo_lag -- unless you can be sure that the data will only be a particular size (and if that is required, then toss in an assert() on the size, just-in-case.
Iugo
Iugo on 3 Oct 2020
So what do you suggest? I'm not quite understanding what to do...

Sign in to comment.

Categories

Find more on Gravitation, Cosmology & Astrophysics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!