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 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Kirby Fears
Kirby Fears am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by