Matlab: how to use an array in a matrix

  • Context: MATLAB 
  • Thread starter Thread starter elham.n
  • Start date Start date
  • Tags Tags
    Array Matlab Matrix
Click For Summary

Discussion Overview

The discussion revolves around the use of arrays in matrices within MATLAB, specifically focusing on how to create a 2x2 matrix from an array. Participants explore the implications of MATLAB's behavior when manipulating arrays and matrices, and the context includes practical applications in physics-related structures.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant, Elham, seeks to create a 2x2 matrix from an array defined by a frequency range using MATLAB.
  • Another participant questions Elham's goal, suggesting that the output is a 2x2x100 array, which may not align with Elham's expectations.
  • Further replies emphasize that MATLAB operates strictly based on the commands given, indicating that the output is consistent with the input provided.
  • Elham clarifies that the intention is to replace elements of the array within the matrix for use as a transfer matrix in PC structures, indicating a need for a square matrix for multiplication purposes.
  • Elham mentions resolving the issue using a FOR loop, suggesting a workaround to achieve the desired matrix structure.

Areas of Agreement / Disagreement

Participants express differing views on the output generated by MATLAB and the interpretation of the array's structure. There is no consensus on the best approach to achieve Elham's goal, as the discussion remains unresolved regarding the optimal method for creating the desired matrix.

Contextual Notes

There are limitations in understanding the specific requirements for the matrix structure and the implications of using arrays versus loops in MATLAB. The discussion does not clarify the mathematical steps necessary to transition from the current output to the desired 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 a lot.

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 a lot..I solved this problem with a FOR loop.
thank u.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K