Hi, does anyone know how to stop my for loop overwriting? I need my answer to be a matrix with each element being a 2x2 matrix also.

1 次查看(过去 30 天)
[M,N] = size(MagGridForceAX); % Establish dimensions for row and column loop counters
for i = 1:M
for j = 1:N
% Creates coefficients for the simultaneous equations of F1 and F2
% based on sum of x and sum of y forces equalling zero
CoefficientMatrix = [MagGridForceAX(i,j) MagGridForceBX(i,j); MagGridForceAY(i,j) MagGridForceBY(i,j)]
% Forces Matrix solving for forces in beams in each x and y
% coordinate
ForcesMatrix = CoefficientMatrix\P;
end
end

回答(1 个)

Walter Roberson
Walter Roberson 2022-9-17
ForcesMatrix{i, j} = CoefficientMatrix\P;
The result will be a cell array that contains numeric arrays.
You could also do
ForcesMatrix(:, :, i, j) = CoefficientMatrix\P;
The result would be a 2 x 2 x M x N numeric array.

类别

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

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by