Error with transpose/permute

조회 수: 4 (최근 30일)
Iugo
Iugo 2020년 10월 2일
댓글: Iugo 2020년 10월 3일
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
Rik 2020년 10월 2일
What is the full error message? It is unclear which command in your code triggers the error.
Iugo
Iugo 2020년 10월 2일
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');

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
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
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.
Iugo
Iugo 2020년 10월 3일
So what do you suggest? I'm not quite understanding what to do...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Gravitation, Cosmology & Astrophysics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by