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 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Kirby Fears
Kirby Fears le 6 Avr 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.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by