Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to define a matrix of variables in matlab?

Status
Not open for further replies.

Fractional-N

Full Member level 1
Full Member level 1
Joined
Oct 15, 2007
Messages
97
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
2,071
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!
 

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?
 

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!
 

matlab variable matrix

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

define variable in matlab

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

    Fractional-N

    Points: 2
    Helpful Answer Positive Rating

    spur

    Points: 2
    Helpful Answer Positive Rating
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
 

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?
 

Re: define variable in matlab

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
 

Re: define variable in matlab

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

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

Re: define variable in matlab

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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top