MATLAB: Subscript indices must either be real positive integers or logicals.

indexingstruct

Hi,
I see I am really bad at indexing so if someone could tell me some general rules (but less general than in online tutorials) I would be grateful.
*Subscript indices must either be real positive integers or logicals.
Error in PL2ex1 (line 4) meandata = mean(nonoise.data_out);*
File to read was uploaded.
%PL2ex1
nonoise = load('verg1');
meandata = mean(nonoise.data_out);
trials = repmat(meandata, 1000, 1);
%add noise with normal distribution (randn) and repeat
sigma = randn(1);
for i = 1:1000
trials(i) = trials(i) + randn(1)*randn(size(trials(i)));
end
%compare plots and mean of trials
x = linspace(0, 10); % define axis x
figure
subplot(3,3,1)
n =(randi(1000));
plot(x, trials(n))
title(sprintf('Trial %d', n))
subplot(3,3,2)
n =(randi(1000));
plot(x, trials(n))
title(sprintf('Trial %d', n))
subplot(3,3,3)
n =(randi(1000));
plot(x, trials(n))
title(sprintf('Trial %d', n))
subplot(3,3,4)
n =(randi(1000));
plot(x, trials(n))
title(sprintf('Trial %d', n))
subplot(3,3,5)
n =(randi(1000));
plot(x, trials(n))
title(sprintf('Trial %d', n))
subplot(3,3,6)
n =(randi(1000));
plot(x, trials(n))
title(sprintf('Trial %d', n))
subplot(3,3,7)
n =(randi(1000));
plot(x, trials(n))
title(sprintf('Trial %d', n))
subplot(3,3,8)
n =(randi(1000));
plot(x, trials(n))
title(sprintf('Trial %d', n))
%mean
subplot(3,3,9)
means = zeros(1,400);
for i = 1:400
means(1,i) = mean(trials(:,i));
end
plot(x, means)
title('Means')

Best Answer

In the Command Window, type:
whos mean
The output should be nothing (just the >> cursor).
If you get something like this:
Name Size Bytes Class Attributes
mean 1x1 8 double
that means you have assigned a variable to ‘mean’, ‘overshadowing’ the mean function.
Solution: Rename the variable.