I want to make several matrices from variables taken from user in a loop while performing some operation on them. I have attached a simplified code for my problem. So I want matrices from 1 to k but it is not working. Guide plz

1 次查看(过去 30 天)
for i=1:k %loop for data input of k layers
E1(i)=input ('Enter E1 ');
E2(i)=input ('Enter E2 ');
v12(i)=input ('Enter v12 ');
G12(i)=input ('Enter G12 ');
%calculation of paramters for the same layer
a(i)=E1(i)+E2(i)^2;
b(i)=E1(i)+E2(i);
c(i)=E1(i)+2*v12(i));
d(i)=E1(i)+2*G12(i);
e(i)=E2(i)-E1(i);
f(i)=v12+G12;
%stacking them in a matrix for that layer
Matrix(i)=[a(i) b(i) c(i); c(i) d(i) e(i); d(i) e(i) f(i)]
end

采纳的回答

Kirby Fears
Kirby Fears 2016-4-6
Try this out.
maxLoops = 10; % set this value
matrixCollection = cell(maxLoops,1); % Initialize matrix collection
for i = 1:maxLoops,
% get inputs
% perform calculations
% stacking them in a matrix for that layer
matrixCollection{i}=[a(i) b(i) c(i); c(i) d(i) e(i); d(i) e(i) f(i)];
end
Each matrix will be stored within cells of the cell array called matrixCollection.
Hope this helps.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by