Store tensor history into multidimensional array
Show older comments
Dear all,
I read the documentatuin on Multidimensional Arrays and I haven't been able to find a solution to my problem.
I have a tensor history like this:
s11 = [xx1, xx2, xx3];
s22 = [yy1, yy2, yy3];
s33 = [zz1, zz2, zz3];
s12 = [xy1, xy2, xy3];
s13 = [xz1, xz2, xz3];
s23 = [yz1, yz2, yz3];
I want to store these tensor component histories in a single multidimensional array TENSOR, such that each slice of the array is a complete stress tensor at a certain point in time, e.g.;
>>TENSOR(:, :, 1.0)
xx1 xy1 xz1
xy1 yy1 yz1
xz1 yz1 zz1
>>TENSOR(:, :, 2.0)
xx2 xy2 xz2
xy2 yy2 yz2
xz2 yz2 zz2
(and so on)
I know how to create a multidimensional array in individual slices. For example, I could simply define the first slice then use
TENSOR(:, :, n) = [s11(n), s12(n), s13(n); s12(n), s22(n), s23(n); s13(n), s23(n), s33(n)];
To add the next slide. However, I would like to define the array in a single assignment, since the whole point of the exercise is to avoid inefficient loops.
I would greatly appreciate any advice!
Best regards,
Louis
1 Comment
Accepted Answer
More Answers (1)
Daniel kiracofe
on 4 Dec 2016
As far as I am aware, it is not possible to do what you want in matlab. There is no such thing as a 3-dimensional array literal, which is what you want. It is possible in some programming languages, such as C++, but not matlab. The only way I can think of do it without loops is to create a 1D array and then reshape it. e.g:
X = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27];
y = reshape(X, [3 3 3])
which would give you this output:
y =
ans(:,:,1) =
1 4 7
2 5 8
3 6 9
ans(:,:,2) =
10 13 16
11 14 17
12 15 18
ans(:,:,3) =
19 22 25
20 23 26
21 24 27
Depending on what you are trying to do, you may find this to be useful. I've not used it, and the documentation on their website is sparse, but it is a toolbox for tensor manipulation in matlab which may helpful
Categories
Find more on Stress and Strain 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!