Thread Subject: Read in a m-file

Subject: Read in a m-file

From: Daniel Eliasson

Date: 19 Mar, 2009 10:37:01

Message: 1 of 6

Hello!

At a certaint point in my program I want to read in some constants that I have written down in another m-file (materialconstants.m).
How do I do that? I cant figure out the command fopen.
I know I could just run the materialconstans.m file and then my program, but I dont want to do that...

Subject: Read in a m-file

From: Rich Ellis

Date: 19 Mar, 2009 14:01:14

Message: 2 of 6

If you are using MATLAB Version 7.6 or later, you might consider using a
class that defines named constants. See: Defining Named Constants in the
MATLAB documentation, which is available at:

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/bru76zw-1.html

"Daniel Eliasson" <danielel@kth.se> wrote in message
news:gpt78d$pps$1@fred.mathworks.com...
> Hello!
>
> At a certaint point in my program I want to read in some constants that I
> have written down in another m-file (materialconstants.m).
> How do I do that? I cant figure out the command fopen.
> I know I could just run the materialconstans.m file and then my program,
> but I dont want to do that...

Subject: Read in a m-file

From: Daniel Eliasson

Date: 19 Mar, 2009 15:10:17

Message: 3 of 6

"Rich Ellis" <rich@mathworks.com> wrote in message <gptj7d$pqb$1@fred.mathworks.com>...
> If you are using MATLAB Version 7.6 or later, you might consider using a
> class that defines named constants. See: Defining Named Constants in the
> MATLAB documentation, which is available at:
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/bru76zw-1.html
>
> "Daniel Eliasson" <danielel@kth.se> wrote in message
> news:gpt78d$pps$1@fred.mathworks.com...
> > Hello!
> >
> > At a certaint point in my program I want to read in some constants that I
> > have written down in another m-file (materialconstants.m).
> > How do I do that? I cant figure out the command fopen.
> > I know I could just run the materialconstans.m file and then my program,
> > but I dont want to do that...
>

Im using Matlab 2008b.
Thanks, I will check it out

Subject: Read in a m-file

From: Daniel Eliasson

Date: 20 Mar, 2009 09:54:01

Message: 4 of 6

"Daniel Eliasson" <danielel@kth.se> wrote in message <gptn8p$bm0$1@fred.mathworks.com>...
> "Rich Ellis" <rich@mathworks.com> wrote in message <gptj7d$pqb$1@fred.mathworks.com>...
> > If you are using MATLAB Version 7.6 or later, you might consider using a
> > class that defines named constants. See: Defining Named Constants in the
> > MATLAB documentation, which is available at:
> >
> > http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/bru76zw-1.html
> >
> > "Daniel Eliasson" <danielel@kth.se> wrote in message
> > news:gpt78d$pps$1@fred.mathworks.com...
> > > Hello!
> > >
> > > At a certaint point in my program I want to read in some constants that I
> > > have written down in another m-file (materialconstants.m).
> > > How do I do that? I cant figure out the command fopen.
> > > I know I could just run the materialconstans.m file and then my program,
> > > but I dont want to do that...
> >

Is this something that will work even if the constants are vectors?
like E=[12 33 56]
...
?

Subject: Read in a m-file

From: Aaron Callard

Date: 20 Mar, 2009 13:02:01

Message: 5 of 6

"Daniel Eliasson" <danielel@kth.se> wrote in message <gpvp3p$12k$1@fred.mathworks.com>...
> "Daniel Eliasson" <danielel@kth.se> wrote in message <gptn8p$bm0$1@fred.mathworks.com>...
> > "Rich Ellis" <rich@mathworks.com> wrote in message <gptj7d$pqb$1@fred.mathworks.com>...
> > > If you are using MATLAB Version 7.6 or later, you might consider using a
> > > class that defines named constants. See: Defining Named Constants in the
> > > MATLAB documentation, which is available at:
> > >
> > > http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/bru76zw-1.html
> > >
> > > "Daniel Eliasson" <danielel@kth.se> wrote in message
> > > news:gpt78d$pps$1@fred.mathworks.com...
> > > > Hello!
> > > >
> > > > At a certaint point in my program I want to read in some constants that I
> > > > have written down in another m-file (materialconstants.m).
> > > > How do I do that? I cant figure out the command fopen.
> > > > I know I could just run the materialconstans.m file and then my program,
> > > > but I dont want to do that...
> > >
>
> Is this something that will work even if the constants are vectors?
> like E=[12 33 56]
> ...
> ?

I think you're making more effort out of this than you probably have too.

Rather than scan through another m file. would it not be much easier to set up a script/function which is called by both functions which initializes these variables. This way they both will still have the same values but with very little programing involved. It's also alot more readable.

Aaron

Subject: Read in a m-file

From: Rich Ellis

Date: 20 Mar, 2009 15:06:43

Message: 6 of 6

The constant property can be anything, including an expression. Here's a
simple example.

classdef MyConst
   properties (Constant = true)
      A = magic(4);
   end
end

Put MyConst.m on your MATLAB path and you can reference A with a statement
like:

>>MyConst.A
ans =

    16 2 3 13
     5 11 10 8
     9 7 6 12
     4 14 15 1

"Daniel Eliasson" <danielel@kth.se> wrote in message
news:gpvp3p$12k$1@fred.mathworks.com...
> "Daniel Eliasson" <danielel@kth.se> wrote in message
> <gptn8p$bm0$1@fred.mathworks.com>...
>> "Rich Ellis" <rich@mathworks.com> wrote in message
>> <gptj7d$pqb$1@fred.mathworks.com>...
>> > If you are using MATLAB Version 7.6 or later, you might consider using
>> > a
>> > class that defines named constants. See: Defining Named Constants in
>> > the
>> > MATLAB documentation, which is available at:
>> >
>> > http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/bru76zw-1.html
>> >
>> > "Daniel Eliasson" <danielel@kth.se> wrote in message
>> > news:gpt78d$pps$1@fred.mathworks.com...
>> > > Hello!
>> > >
>> > > At a certaint point in my program I want to read in some constants
>> > > that I
>> > > have written down in another m-file (materialconstants.m).
>> > > How do I do that? I cant figure out the command fopen.
>> > > I know I could just run the materialconstans.m file and then my
>> > > program,
>> > > but I dont want to do that...
>> >
>
> Is this something that will work even if the constants are vectors?
> like E=[12 33 56]
> ...
> ?

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com