필터 지우기
필터 지우기

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