- 22nd June 2008, 17:27 #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!

- 22nd June 2008, 17:39 #2

- 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?

- 22nd June 2008, 17:39

- 22nd June 2008, 18:21 #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!

- 22nd June 2008, 18:21

- 22nd June 2008, 19:31 #4

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

- 19th July 2008, 15:24 #5

- Join Date
- Nov 2005
- Location
- EGYPT
- Posts
- 1,347
- Helped
- 214 / 214
- 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.

- 19th July 2008, 15:24

- 3rd June 2011, 09:50 #6

- 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

- 11th July 2012, 11:06 #7

- 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?

- 15th July 2013, 03:39 #8

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

- 15th July 2013, 03:52 #9
## Re: define variable in matlab

1 members found this post helpful.

- 16th July 2013, 00:31 #10

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

- 16th July 2013, 06:53 #11