MATLAB Matlab: how to use an array in a matrix

AI Thread Summary
The discussion revolves around the creation of a 2x2 matrix from a given array in MATLAB. The user initially attempts to construct a matrix using the array `a` and encounters an issue where the output is a 2x2x100 array instead of the desired 2x2 matrix. Clarification is sought on how to achieve a standard 2x2 matrix, with the user expressing the need for this format to use as a transfer matrix in photonic crystal structures. The confusion stems from not realizing that the output was indeed a multi-dimensional array. Ultimately, the user resolves the issue by implementing a FOR loop to achieve the desired matrix format.
elham.n
Messages
4
Reaction score
0
hi all..

I have a 2x2 matrix and an array , for example:

a=linspace(0,12) %this is my frequency range.

B=[2*a 3*a-1
a./2 a]

this one does not results a 2x2 matrix, that I need it to have ...B2xB1xB
how could i get a 2x2 matrix? should i use a loop instead of an array?
tnx alot.

Elham
 
Physics news on Phys.org
What are you trying to accomplish here, elham?
 
With what?

What you have here a 2x2x100 array -- which is exactly what you asked for. You just don't know that that is what you asked for.

What you want is something different, apparently a plain old vanilla 2x2 matrix. I don't know how to read your mind, let alone a dumb program like Matlab. It only does what you tell it to do. Matlab, like all other languages built to date, does not have a DWIM (do what I mean) command.
 
Matlab did exactly what you told it to do. That apparently is not what you want it to do.

So what exactly are you trying to accomplish?
 
I know what u mean!and I do not expect MATLAB to do s.th strange..
I want to replace this array's elements in this matrix.
i will use a matrix like this as the transfer matrix in PC structures,and multiplicantion of these matrices for every layer,but with this selected array , i face some problems. and multiplicantion of these matrices is impossible.
so i need square matrix..and I was only confused
tnx alot..I solved this problem with a FOR loop.
thank u.
 
Back
Top