How can I use loops to reduce the code size

1 次查看(过去 30 天)

采纳的回答

Luna
Luna 2018-11-29
编辑:Luna 2018-11-30
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

更多回答(1 个)

Jay Mistry
Jay Mistry 2018-11-29
Data file

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by