---
+ Post New Thread
Results 1 to 11 of 11
  1. #1
    Full Member level 1
    Points: 2,037, Level: 10
    Fractional-N's Avatar
    Join Date
    Oct 2007
    Posts
    97
    Helped
    20 / 20
    Points
    2,037
    Level
    10

    matlab define matrix

    How to define a matrix of variables in matlab?

    For example I want a matrix like:

    a=[sin(t) cos(t);cos(t) sin(t)]

    so that "t" be a variable, when I assign t=.5 it should give to me

    [0.4796 0.8776;0.8776 0.4796]

    how should I do that?

    help me if u can! thanks!

    •   Alt22nd June 2008, 17:27

      advertising

        
       

  2. #2
    Advanced Member level 5
    Points: 40,208, Level: 49

    Join Date
    Apr 2002
    Location
    USA
    Posts
    3,944
    Helped
    651 / 651
    Points
    40,208
    Level
    49

    matlab matrix variables

    I don't quite understand your question. If I simply type your two statements into MATLAB:

    t = .5
    a = [sin(t) cos(t);cos(t) sin(t)]


    it displays the resulting matrix as you requested:

    0.479425538604203 0.877582561890373
    0.877582561890373 0.479425538604203


    Or do you want it formatted with square brackets and semicolon?



  3. #3
    Full Member level 1
    Points: 2,037, Level: 10
    Fractional-N's Avatar
    Join Date
    Oct 2007
    Posts
    97
    Helped
    20 / 20
    Points
    2,037
    Level
    10

    matlab matrix with variables

    No,
    you should type the matrix definition first
    I want to define a matrix (containing a variable such as "t")
    then put it in a loop, and change the variable, and get different values

    -----------
    you should type: ( as I did! )

    >> syms t
    >> a=[sin(t) cos(t);cos(t) sin(t)]

    a =

    [ sin(t), cos(t)]
    [ cos(t), sin(t)]

    >> t=1.2;
    >> a

    a =

    [ sin(t), cos(t)]
    [ cos(t), sin(t)]

    -----------------------------
    is it clear?! I want "t" in the matrix to be a variable!

    How can I do that?
    thanks!



  4. #4
    Advanced Member level 5
    Points: 40,208, Level: 49

    Join Date
    Apr 2002
    Location
    USA
    Posts
    3,944
    Helped
    651 / 651
    Points
    40,208
    Level
    49

    matlab variable matrix

    Oh, that looks like Maple symbolic processing. Sorry, I've never explored that aspect of MATLAB.



    •   Alt22nd June 2008, 19:31

      advertising

        
       

  5. #5
    Advanced Member level 4
    Points: 11,529, Level: 25
    safwatonline's Avatar
    Join Date
    Nov 2005
    Location
    EGYPT
    Posts
    1,347
    Helped
    213 / 213
    Points
    11,529
    Level
    25

    define variable in matlab

    Code:
    syms t
    a=[sin(t) cos(t);cos(t) sin(t)] 
    a=subs(a,t,0.1)


    2 members found this post helpful.

    •   Alt19th July 2008, 15:24

      advertising

        
       

  6. #6
    Newbie level 2
    Points: 278, Level: 3

    Join Date
    Jun 2011
    Posts
    1
    Helped
    0 / 0
    Points
    278
    Level
    3

    Re: matlab define matrix

    Hi ,

    Is there any way to write a for loop in MATLAB to read the files i.e. texts that
    are saved in a folder and do some operation on each in every iteration. So
    let say if I have files 1.txt, 2.txt,,... all saved in a folder called
    LOSS. i want to open 1.txt first----> do some calculation and display the
    result, then open 2.txt and do the same calculation, then 3.txt and so on.
    thanks

    Anvari



  7. #7
    Newbie level 1
    Points: 80, Level: 1

    Join Date
    Jul 2012
    Posts
    1
    Helped
    0 / 0
    Points
    80
    Level
    1

    Re: matlab define matrix

    a=[-0.5 0 0 0 ;1 -1 0 0;0 1 -3 0;0 0 1 -10];
    k1=char;
    k2=char;
    k3=char;
    k4=char;
    s=char;
    c=[k1 k2 k3 k4];
    b=[4.5;1;0;0];
    i=eye(4);
    q=b*c;
    t=s*i;
    w=t-q;
    e=det(w);

    %++++++++++++++++++++++++++++++why this not true?



  8. #8
    Newbie level 2
    Points: 16, Level: 1

    Join Date
    Jul 2013
    Posts
    2
    Helped
    0 / 0
    Points
    16
    Level
    1

    Re: define variable in matlab

    Quote Originally Posted by safwatonline View Post
    Code:
    syms t
    a=[sin(t) cos(t);cos(t) sin(t)] 
    a=subs(a,t,0.1)
    Help please.
    the above code just substitute the t with 0.1 and returns
    a =

    [ sin(1/10), cos(1/10)]
    [ cos(1/10), sin(1/10)]

    how can i convert this into real values?
    please help



  9. #9
    Full Member level 1
    Points: 2,037, Level: 10
    Fractional-N's Avatar
    Join Date
    Oct 2007
    Posts
    97
    Helped
    20 / 20
    Points
    2,037
    Level
    10

    Re: define variable in matlab

    Quote Originally Posted by jithjith View Post
    Help please.
    the above code just substitute the t with 0.1 and returns
    a =

    [ sin(1/10), cos(1/10)]
    [ cos(1/10), sin(1/10)]

    how can i convert this into real values?
    please help
    something is wrong with your MATLAB
    here is what I get when I copy those commands into MATLAB
    Code:
    >> syms t
    a=[sin(t) cos(t);cos(t) sin(t)] 
    a=subs(a,t,0.1)
     
    a =
     
    [ sin(t), cos(t)]
    [ cos(t), sin(t)]
     
     
    
    a =
    
        0.0998    0.9950
        0.9950    0.0998


    1 members found this post helpful.

  10. #10
    Newbie level 2
    Points: 16, Level: 1

    Join Date
    Jul 2013
    Posts
    2
    Helped
    0 / 0
    Points
    16
    Level
    1

    Re: define variable in matlab

    Is there a way in which I can resolve this.........?
    Thanks for the help.



  11. #11
    Full Member level 1
    Points: 2,037, Level: 10
    Fractional-N's Avatar
    Join Date
    Oct 2007
    Posts
    97
    Helped
    20 / 20
    Points
    2,037
    Level
    10

    Re: define variable in matlab

    Quote Originally Posted by jithjith View Post
    Is there a way in which I can resolve this.........?
    Thanks for the help.
    you've used "format rat" . to go back to default use:
    Code:
    format



+ Post New Thread
Please login