# How to define a matrix of variables in matlab?

1. ## 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!

•

2. ## 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. ## 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. ## matlab variable matrix

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

5. ## 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.

•

6. ## 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. ## 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. ## Re: define variable in matlab

Originally Posted by safwatonline
Code:
```syms t
a=[sin(t) cos(t);cos(t) sin(t)]
a=subs(a,t,0.1)```
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?

9. ## Re: define variable in matlab

Originally Posted by jithjith
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?
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. ## Re: define variable in matlab

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

•

11. ## Re: define variable in matlab

Originally Posted by jithjith
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`

--[[ ]]--