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 view (last 30 days)
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

Accepted Answer

Kirby Fears
Kirby Fears on 6 Apr 2016
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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!