How to avoid the ??? Index exceeds matrix dimensions.

2 views (last 30 days)
Hai everybody. I m a new student in Matlab and I am doing a small project in Matlab regarding forecasting Temperature inside , Humidity Inside, CFM of ceiling fan in a specific example of indoor house, and Temperature Out and Humidity Out. Now the problem is i couldnt get the excepted FCM to show the memory. Here I am using coding with Differential Hebbian Rule to train the network. Unfortunately I cannot get the answer for the corrupted figures. Please guide me if I am wrong.
clc
%clear all
% DATASET STRUCTURE
Original=[ % this is a raw dataset of 5 variables and 48 samples
% var1: temp in var2:humidity in var3:cfm of ceiling fan var4:temp out var5:humidity out ...
29 59 1725 35 55
29 59 2535 35 55
29 58 3600 35 55
30 51 1725 36 57
30 49 2535 36 57
30 49 3600 36 57
36 42 1725 34 52
36 42 2535 34 52
34 43 3600 34 52
36 44 1725 35 54
36 44 2535 35 54
35 44 3600 35 54
35 42 1725 35 57
35 44 2535 35 57
33 45 3600 35 57
32 48 1725 26 71
32 48 2535 26 71
30 49 3600 26 71
30 57 1725 25 78
30 57 2535 25 78
29 59 3600 25 78
31 59 1725 22 84
31 59 2535 22 84
30 59 3600 22 84
26 59 1725 29 55
26 59 2535 29 55
27 58 3600 29 55
27 51 1725 29 57
27 49 2535 29 57
30 49 3600 29 57
29 42 1725 30 52
31 42 2535 30 52
33 43 3600 30 52
32 44 1725 30 54
32 44 2535 31 54
32 44 3600 31 54
31 42 1725 30 57
31 44 2535 30 57
31 45 3600 29 57
29 48 1725 28 71
29 48 2535 28 71
29 49 3600 28 71
28 57 1725 27 78
28 57 2535 27 78
28 57 3600 27 78
27 59 1725 27 84
27 59 2535 27 84
27 59 3600 27 84];
DataSet=(Original-1)./6; % we scale down all data within (0,1)
% TRAINING INITIALIZATION
Rec=size(DataSet,1); % returns Rec=48
Var=size(DataSet,2); % returns Var=5
alpha=0.02; % alpha: learning rate
W= repmat(0,Var,Var); % W is adjacency weights matrix
% TRAINING
start=clock; % read system time
for Epoch=1:1000 % for 1000 times we repeat training for all (samples)
for sample=1:Rec % loop for learning all samples
X=DataSet(sample,:); % pick a sample
Y=X*W;
for j=1:Var
for i=1:Var
delta=alpha*(Y(j)-X(j))*(Y(i)-X(i)); % differential Hebbian learning rule
W(i,j)=W(i,j)+delta;
end
end
end
end
stop=clock; % read system time (STOP time)
Run_Time= 60*(stop(5)-start(5))+stop(6)-start(6) % computational cost
surf(W) % w is the knowledge base (adjacency model)
Memory=DataSet*W;
Error=sqrt(sum(sum((Memory-DataSet).^2))./(Rec*Var)) % all data RMS error
%--------------------------------------------------------------------------
% TESTING
testRecord= [20 50 1725 35 55];% alages: this is the corrupted sample done by me
testRecord=(testRecord-1)./6; % standardization by squashing within 0,1
test=testRecord;
for equ=1:10
test=test*W; % for 10 times, we apply the model (W) to the test record to rebuild it
for fix=1:30 % remeber, every time those certain values within test record must be retained
test(fix*6-5:fix*6-1)=testRecord(fix*6-5:fix*6-1);
end
end
test=test*6+1 % back to Original data format
max(abs(Original(1,:)-test)) % now compare the rebuilt record #1 with the original record #1 to get the maximum error
  5 Comments
Walter Roberson
Walter Roberson on 15 Mar 2014
It is not recommended to use "fix" as a variable name, as "fix" is the name of a MATLAB routine.
You have not indicated what "fix" was initialized to. If it was initialized to 1, then 1*3-5 is 3-5 which is -2 which is not a positive integer and so cannot be a subscript.
Alagesan
Alagesan on 16 Mar 2014
can anyone tell me the function for fix??

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 16 Mar 2014
You ask "can anyone tell me the function for fix??" Use k or loopIndex or counter or any other loop index/iteration variable that is not a keyword or reserved function. If in doubt, type "which k" or "whos k" on the command line to see if it's in use already. You might also use parentheses around your index range fix*3-5:fix*3-1 to make it more clear to the reader what you want. For example
5:8-1
5:(8-1)
(5:8)-1
ans =
5 6 7
ans =
5 6 7
ans =
4 5 6 7
  4 Comments
Image Analyst
Image Analyst on 16 Mar 2014
Looks like you posted a separate message for this so we'll continue the discussion there.
Alagesan
Alagesan on 16 Mar 2014
okie. I separated it. So it wont looks fussy..thank you

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!