Error with transpose/permute
3 views (last 30 days)
Show older comments
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
Answers (1)
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,:))
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!