Borrar filtros
Borrar filtros

Matlab script question(quick)

2 visualizaciones (últimos 30 días)
Eugene
Eugene el 11 de Jun. de 2012
Say that I have a script.m file and within that file there are functions with different variables.
And then I have a txt file with a matrix of numbers that I would like to plug into those variables in the m file, how would I got about doing this?
I have columns of the matrix assigned to different variables, however I have no idea how to get the script.m file to communicate with the txt file so that it can do it's "plug-and-chugging".
Thank you for your time!

Respuestas (1)

Walter Roberson
Walter Roberson el 11 de Jun. de 2012
It is not possible to have functions inside a script file. Functions can only go inside function files.
To read values from a file, use load() or importdata() or uiimport() or csvread() or xlsread() or dlmread() or textscan() or the basic I/O functions such as fgetl() and fscanf().
There are lot of examples around of passing variables into functions. See http://www.mathworks.com/help/techdoc/ref/function.html
  2 comentarios
Eugene
Eugene el 11 de Jun. de 2012
Opps! Take for example my script.m file has "A + B", and I have a txt file that has two columns with x rows. I have assigned one of those columns as A, and another as B.
My question is how do I run the script.m file so that it uses those A and B values from the txt file? The only message I seem to get is that I have undefined variables for A and B, when I have already assigned them as such.
Walter Roberson
Walter Roberson el 11 de Jun. de 2012
Your description appears to be contradictory. If you have assigned values to A and B, then those values will be available to any script you run.
I suspect you are using functions rather than scripts. Please read http://www.mathworks.com/help/techdoc/matlab_prog/f7-38085.html

Iniciar sesión para comentar.

Categorías

Más información sobre Standard File Formats en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by