How can I use loops to reduce the code size

11 views (last 30 days)
Jay Mistry
Jay Mistry on 29 Nov 2018
Reopened: Walter Roberson on 20 Dec 2018
Thanks a lot
  2 Comments
Luna
Luna on 30 Nov 2018
I have edited the code check again if it gives correct result of yFinal.

Sign in to comment.

Accepted Answer

Luna
Luna on 29 Nov 2018
Edited: Luna on 30 Nov 2018
You can try this, I haven't checked working correctly since there is no data.
clc
clear all
C1 = xlsread('data1.xlsx');
y = C1(1:400,13);
R0 = [];
Z = [];
m=1;
for i=5:11
x{m} = C1(1:400,i);
m=m+1;
end
for j = 1:7
for k = 1:7
R(j,k) = mean(x{j}.*x{k});
end
end
for n = 1:7
R0 = [R0; mean(x{n}.*y)];
Z = [Z,x{n}];
end
yFinal = zeros(400,1);
A = pinv(R)*(R0);
for i = 1:7
temp = A(i).*x{i};
yFinal = yFinal+temp;
end

More Answers (1)

Jay Mistry
Jay Mistry on 29 Nov 2018
Data file

Categories

Find more on Encryption / Cryptography in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!