How to make indices integers/logicals while filling 3D matrix with data?

1 view (last 30 days)
Hello,
I got error: 'Subscript indices must either be real positive integers or logicals.'
While filling 3D matrix using triple loop:
function [m3d] = matrixfill(ROIs, dm)
%Filling 3D matrix with phase difference values for ROIs pairs and saving
%to .mat file.
ROIs_length = length(ROIs);
time_length=size(dm,1); %to define time we need to know length of time series
times=0:1.83:((time_length-1)*1.83); %time defined
for d=1:ROIs_length
x=[times; dm(:,ROIs(d))'];
for e=1:ROIs_length
y=[times; dm(:,ROIs(e))'];
[Rsq,period,scale,coi,sig95,X,Y,Wxy,sWxy,ejpdXY]=wtc_AA(x,y,'MonteCarloCount',1);
period_length=length(period);
for f = 1:period_length
freq=period(f);
m3d = zeros(period_length,ROIs_length,time_length); %3D matrix filled with zeros
m3d(d,x,f) = mean(angle(Wxy(freq,:)));
%error: Subscript indices must either be real positive integers or logicals.
%filling matrix with means of phase difference
end
end
filename=sprintf('for_ROI%d.mat',d);
save(filename);
end
end
How to fix it?
Thanks in advance.
Kasia

Accepted Answer

dpb
dpb on 2 May 2014
You defined
times=0:1.83:((time_length-1)*1.83); %time defined
so times are not integer-valued, then later on did the following
for d=1:ROIs_length
x=[times; dm(:,ROIs(d))'];
...
m3d(d,x,f) = mean(angle(Wxy(freq,:)));
%error: Subscript indices must either be real positive integers or logicals.
Hence, x cannot be used as a subscripting variable--you can't have the 1.83th entry into an array. You'll have to store the array over the numbers 1:length(x) if that's what you want to do but you can't use x as the index.
Not knowing what you're real end objective is, it's hard to say specifically the best solution but one might think about whether there's a real need or the 3D array at all? Just keep the vectors and associate with indices might be simpler?
  2 Comments
Katarzyna Wieciorek
Katarzyna Wieciorek on 2 May 2014
I will try to explain what is the objective of the research to help us find the best solution for my problem.
I analyze the results of fMRI to find what regions of brain at what time were activated during the measurement. The product of my script should be series of files telling what is the mean phase difference between particular ROI (region of interest) and all others at given frequency. It will allow us for Rayleigh circularity test. What other way I can do that?
dpb
dpb on 2 May 2014
Save the data in a linear index for each x in the 2nd dimension from 1:length(x). Associate that index with the vector x values in order to determine the value at that location.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!