Error with transpose/permute
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2020-10-2
What is the full error message? It is unclear which command in your code triggers the error.
回答(1 个)
Walter Roberson
2020-10-2
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 个评论
Walter Roberson
2020-10-3
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!