How to read and write this file?

% h11 h12 h22
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065
-1.00002065 -1.00002065 -1.00002065

 Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 30 de Nov. de 2014
[h11,h12,h22]=textread('data.txt','%f %f %f','headerlines',2);

7 comentarios

dpb
dpb el 30 de Nov. de 2014
might try importdata -- not sure about it and the blank line
Uday padidela
Uday padidela el 30 de Nov. de 2014
Editada: Uday padidela el 30 de Nov. de 2014
Thank you Mohammad Abouali...
I tried to use textread, but it reads and write all the h11, h12 and h22 values in one column. Its difficult for me to use these values again.
I want to read and write the values h11, h12 and h22 values in 3 different coumns and use these values in solving an expression.
Thank you again.
Uday padidela
Uday padidela el 30 de Nov. de 2014
I have attached the file below if you would like to see it for further clarification.
Mohammad Abouali
Mohammad Abouali el 30 de Nov. de 2014
Did you use the exact command. I used the following command:
[h11,h12,h22]=textread('h_size_Ar_Kr_HNC_chk.txt','%f %f %f', 'headerlines',1);
and each column was loaded separately on h11, h12, and h22.
Uday padidela
Uday padidela el 30 de Nov. de 2014
Thank you again...
Yeah It reads perfectly now..
but I came across the error "Subscript indices must either be real positive integers or logicals."
I have a written a code like this, could you tel me is there any mistake I have done in the code..
I have attached it below
thank you
Image Analyst
Image Analyst el 30 de Nov. de 2014
It sounds like Mohammad's suggestion got you working so I'll ignore your comment to me below but you should mark his answer as Accepted to give him reputation points. My readtable answer should also have worked. You can also Vote for any answer that you liked even though you can accept only one.
I can't really tell if your code has any mistakes or not, just glancing at it. It looks like an alphabet soup of single and double letter variable names that's virtually impossible to follow without some kind of printed equation (that I imagine your variable names correspond to). But if it works, then it works. My only suggestion would be to put in many, many more comments and use more descriptive variable names so that people can follow it. It just makes your code more maintainable. Even by you. If you were to look at that code 5 years from now, would you be able to follow it?
Uday padidela
Uday padidela el 1 de Dic. de 2014
I will surely follow your suggestions. It really helps me to follow up my code in future.
Thank you ..

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 30 de Nov. de 2014
Another option, if you can get rid of the % symbol on the first line: readtable():
t = readtable(filename);

3 comentarios

Uday padidela
Uday padidela el 30 de Nov. de 2014
Thank you for your suggestion.
I have a text file in the above mentioned manner.
I want to read the values of h11, h12 and h22 from the file and use these values in solving an expression.
thank you..
Image Analyst
Image Analyst el 30 de Nov. de 2014
Try dlmread with a space delimiter.
By the way, because you're not attaching your text file, it's causing us all of these back and forth guesses instead of letting us try something on your actual file and giving you the answer correctly the first time and making you go hours until you get a good answer. You might want to read our tutorial
Uday padidela
Uday padidela el 30 de Nov. de 2014
I have attached the file below for clarification.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 30 de Nov. de 2014

Comentada:

el 1 de Dic. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by