# i want to extract a matrix from a cell array that consists on a number of 3x3 matrices

1 view (last 30 days)
Mahmoud Chawki on 16 May 2022
Answered: Nipun on 9 Oct 2023
i want to extract a matrix from a cell array that consists on a number of 3x3 matrices
clc
clear all
%Given lamina unidirecton properties E1, E2, G12,v12
n=3;
t= 5; %Ply thickness mm
h=n*t; %thickness of the laminate
E1= 181; %GPA
E2= 10.3; %GPA
G12= 7.17; %GPA
V12= 0.28; %poisson ratio
Nx= 1; %Mpa.mm
Ny= 1; %Mpa.mm
Nxy= 0; %Mpa.mm
Mx= 0;
My=0;
Mxy=0;
Force_vec=[Nx; Ny; Nxy; Mx; My; Mxy];
%Determine stresses and strains in each ply
%First step find Q matrix
tetha=[0 30 -45];
c=cosd(tetha);
s=sind(tetha);
%S matrix calculation
S=[1/E1 -V12/E1 0;-V12/E1 1/E2 0;0 0 1/G12];
%Q matrix calculation
Q=inv(S);
for i=1:numel(tetha)
%Transformation matrix calculation
T{i}=[c(i).^2 s(i).^2 2.*s(i).*c(i); s(i).^2 c(i).^2 -2.*s(i).*c(i); -s(i).*c(i) s(i).*c(i) (c(i).^2)-(s(i).^2)];
%Inverse of the transformation matrix
T_1{i}=inv(T{i});
%R matrix
R{i}=[1 0 0; 0 1 0; 0 0 2];
R_1{i}=inv(R{i});
%S bar matrix calculation
Sbar{i}=R{i}*T_1{i}*R_1{i}*S*T{i}; %results are in 1/GPA
%Q_bar matrix calculation
Qbar{i}=inv(Sbar{i});
end
i want to extract each matrix and save it alone from Qbar which consists of an array of matrices
Mahmoud Chawki on 16 May 2022
I mean extract a matrix from Qbar and assign to a value.
Stephen23 on 16 May 2022
"I mean extract a matrix from Qbar and assign to a value."
The word "extract" does not have a common MATLAB meaning. So I am asking you what you expect to happen, so that we can help you. Consider this simple example:
Qbar = {[11,12;13,14],[21,22;23,24],[31,32;33,34]}
Please show the expected output given this Qbar.

Nipun on 9 Oct 2023
Hi Mahmoud,
I understand that you are trying to extract and save individual matrices from a cell array of matrices, named Qbar. I assume that no changes are required to the code for matrix generation; all matrices saved in the cell array are index retrievable. Additionally, I assume that require a separate entry point (or file) for each saved matrix.
You can use save function to save a variable (in this case, the matrix) to a .mat file. Then, you can leverage load function to load the matrix from .m file . I am attaching an example code below to help with the matrix saving & loading:
Qbar = {[1,2;3,4],[201,89;98,982],[32921,312;3113,3344]};
% saving matrices in file Qbar_matrices_{i}.mat, where i is matrix index in
% Qbar
for i=1:length(Qbar)
file_name = "Qbar_matrices_"+string(i)+".mat";
matrix = Qbar{i};
save(file_name, "matrix")
end
Link to the resources:
1. save to a mat file: https://in.mathworks.com/help/matlab/ref/save.html
2. load from a mat file: https://in.mathworks.com/help/matlab/ref/load.html
Regards,
Nipun