read data from .m file

hi
I want to store different variables in the same .m file,And after I must read these variables one by one. exemple
1
23 3 4
5 6 4
This is contain of .m file.I need to, load this contain, read 1st and 3 rd rows. I hope you help me. thanks

4 comentarios

Walter Roberson
Walter Roberson el 17 de En. de 2012
Discusses proceeded in the duplicate question http://www.mathworks.com/matlabcentral/answers/26116-read-a-line-frome-file
atsprink
atsprink el 13 de Oct. de 2016
Editada: Walter Roberson el 13 de Oct. de 2016
I have the following data in a .m file. I realize this is bad but it is out of my control. I have looked into using fopen and fscanf to read the data. I can duplicate the exact data from the file but I only need part of the data. Please see the attached file for the data I want to read.
%read in data from file
fileId = fopen('pfoutput.m');
opPoints = fscanf(fileId, '%c');
I just want the numeric values.
Walter Roberson
Walter Roberson el 13 de Oct. de 2016
fileId = fopen('pfoutput.m');
datacell = textscan(fileId, '*%f|%f/%f*', 'HeaderLines', 3, 'CollectOutput', 1);
fclose(fileId);
opPoints = datacell{1};
atsprink
atsprink el 14 de Oct. de 2016
awesome...thank you for the help. I was able to make little tweaks to your solution to work as I needed it to.

Iniciar sesión para comentar.

Respuestas (1)

Thomas
Thomas el 17 de En. de 2012

0 votos

Variables are not stored in .m files as they are ASCII, Variables are usually stored in .mat files that matlab can read.

Categorías

Preguntada:

el 14 de En. de 2012

Comentada:

el 6 de Nov. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by