×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How can I read part of a file and edit it in a matlab script?

How can I read part of a file and edit it in a matlab script?

How can I read part of a file and edit it in a matlab script?

(OP)
Hi there I am using a custom-made Matlab s-function script which demands that I know how large my output data is before I intialise it. The problem is I want this to be chosen by a variable rather than me having to manually open the file and change it.

What I need to know is how to go about running an .m script file which does the following:

open another .m file

looked down to the n-th line of this file

replace the first number it finds on this line with one from a variable i choose

save and close the file ready to be run



I want this to be done all within matlab so i can simply run a script to do this.

Would anyone know how I can go about doing this? perhaps a suggestions of a command for each of the steps I need?

I have read into textread but that seems to want to read each word on the line into a seperate variable. Even then, I cant figure out how to write the new value back to the .m file.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources