Clear Filters
Clear Filters

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

1 view (last 30 days)
i want to extract a matrix from a cell array that consists on a number of 3x3 matrices
clear all
%Given lamina unidirecton properties E1, E2, G12,v12
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;
Ny= 1;
Nxy= 0;
Mx= 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];
%S matrix calculation
S=[1/E1 -V12/E1 0;-V12/E1 1/E2 0;0 0 1/G12];
%Q matrix calculation
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
%R matrix
R{i}=[1 0 0; 0 1 0; 0 0 2];
%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
i want to extract each matrix and save it alone from Qbar which consists of an array of matrices
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.

Sign in to comment.

Answers (1)

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")
% loading matrix
load("Qbar_matrices_1.mat", "matrix")
Link to the resources:
  1. save to a mat file:
  2. load from a mat file:


Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!