Subscript indices must either be real positive integers or logicals.
Show older comments
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')
Accepted Answer
More Answers (1)
Roger Stafford
on 20 Mar 2015
0 votes
I would guess that somewhere in your system you have defined a variable named 'mean', in which case matlab misinterprets the calls to the function 'mean' as referring to that variable. That is the only way I can account for the error message. You should never use the names of matlab functions as variables for just this reason.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!