PDA

View Full Version : Naming numbered matrices in Matlab



Matt Gignac
09-18-2005, 03:15 PM
I'm having trouble finding any information on this.

For my composites class, I need to make a program that calculates the off-axis Q and S matrices for each ply, which I will later all need for finding generalized Q and S matrices.

I'd want to do something like Q(i) = Q (which would give me Q(1), Q(2), etc, but the thing is for matrices it will seek out the i'th column, and will give me a message about how the left and right statements have a different number of elements.

Any ideas short of hard coding each new Q in some kind of if, elseif statement? I dont want to do this since the number of plies isnt constant.

I hate programming

Matt Gignac
McGill Racing Team

Matt Gignac
09-18-2005, 03:15 PM
I'm having trouble finding any information on this.

For my composites class, I need to make a program that calculates the off-axis Q and S matrices for each ply, which I will later all need for finding generalized Q and S matrices.

I'd want to do something like Q(i) = Q (which would give me Q(1), Q(2), etc, but the thing is for matrices it will seek out the i'th column, and will give me a message about how the left and right statements have a different number of elements.

Any ideas short of hard coding each new Q in some kind of if, elseif statement? I dont want to do this since the number of plies isnt constant.

I hate programming

Matt Gignac
McGill Racing Team

CMURacing - Prometheus
09-19-2005, 01:27 PM
you want a matrix of matrices eh?

good luck doing it in matlab, i'd do it in your favorite c variant, working off open-source matrix classes, and adapting them to be 3-dimensional.

KevinD
09-19-2005, 03:29 PM
i can help you out, but i think i am not understanding the question. are you trying to have embedded arrays inside an array? i.e. you have a matrix or array of size 3x3 but element (1,1) is of size 2x2 or something to that effect?

matlab is pretty stupid when it comes to arrays and dimension mismatching, but with some practice you will figure out to work around these issues. feel free to e-mail me: kevin at rennlist.net and describe your problem and i will answer it to the best of my ability.


but to start i think your going to have to do something to this effect:
Q = 0; %it helps to know the dimensions to speed up processsing here. define the array size if you can
for j = 1:length(Q)
Q(j) = whatever you want it to be;
end

that will go through the length of your Q array and define each element however you want. if you have an array that is more then one dimension i.e. 2x2, then you will have to embed another for loop inside that one. you can have elements in an array that are arrays themselves, and i can tell you how to do that too if thats what your doing.

not sure if that will help... but let me know what you need!

Matt Gignac
09-19-2005, 07:04 PM
That's initially what I had been trying, but since matlab defines everything as matrices (i.e. a scalar is just a 1x1 matrix), when i tried to define Q(i), i being the index of my for loop, it assumed the i'th column of my matrix Q. So i had an assignment like Q(i)=[a b c; d e f; g h i] and this was the cause of confusion.

I could have just put another for loop in there so that every time i want to stick another matrix in my uber array, it would just shift everything over by 3 columns, but this would prove to be a pain in the ass for what I need these matrices for after.

What I ended up doing is using structures, which is essentially a matrix of whatever, in my case, a matrix of matrices.

So I did:
for i=1:n
blablabla
some calculations, some input
ply(i).Qoffaxis= [Q11 Q12 Q16; Q12 Q22 Q26; Q16 Q26 Q66];
ply(i).Soffaxis= [S11 S12 S16; S12 S22 S26; S16 S26 S66];

end

so ply is my structure, and then Qoffaxis and Soffaxis are my little sub-matrices. I iterate on the structure, and therefore I can recall each individual matrix later on, which is what I needed.

Thanks for the help though

Matt Gignac
McGill Racing Team

Chris Clarke
09-19-2005, 09:10 PM
<BLOCKQUOTE class="ip-ubbcode-quote"><div class="ip-ubbcode-quote-title">quote:</div><div class="ip-ubbcode-quote-content">For my composites class, I need to make a program that calculates the off-axis Q and S matrices for each ply, which I will later all need for finding generalized Q and S matrices. </div></BLOCKQUOTE>


Do you have to create your own program, or do you not have access to any available ones?

KevinD
09-20-2005, 06:59 AM
i'm sure he meant he had to write a script to do the calculations he wanted. it's not really writing a program, but rather programing your script.

ben
09-21-2005, 04:29 AM
<BLOCKQUOTE class="ip-ubbcode-quote"><div class="ip-ubbcode-quote-title">quote:</div><div class="ip-ubbcode-quote-content">Originally posted by Matt Gignac:
I'm having trouble finding any information on this.

For my composites class, I need to make a program that calculates the off-axis Q and S matrices for each ply, which I will later all need for finding generalized Q and S matrices.

I'd want to do something like Q(i) = Q (which would give me Q(1), Q(2), etc, but the thing is for matrices it will seek out the i'th column, and will give me a message about how the left and right statements have a different number of elements.

Any ideas short of hard coding each new Q in some kind of if, elseif statement? I dont want to do this since the number of plies isnt constant.

I hate programming

Matt Gignac
McGill Racing Team </div></BLOCKQUOTE>

Noticed that you used structures. Most of my code does these days.

If you haven't come across them, the file exchange functions mmv2struct and clear_type make using structs really easy.

Ben