For large arrays, Matrix rows carry onto next line theyre written in from a fortran program
43 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Harry Dunn
el 29 de Mzo. de 2022
Comentada: Daksh
el 19 de Dic. de 2022
I am running a fortran program which operates over quite a large gridspace and when i write it to a matlab file it carries some of the values that are meant to be on the same row onto the next line which then means not all rows are the same length. When i decrease the gridspace so that all values of each row stay on the same line it works fine however i need to run it with a larger gridspace.
I have tried to add "..." to each line but to do this for such a large matrix seems like an inefficient solution. I tried to find if a whole section of code could be treated with one "..." but couldnt find anything on it. I have also tried writing to a .dat file which i will then read into matlab but this had lead to further complications.
Any suggestions are appreciated.
Thank you.
1 comentario
Respuesta aceptada
Jan
el 4 de Abr. de 2022
Storing large blocks of data as source code is a bad idea. Text or binary files are much better.
Matlab tries to be smart and let you omit the separators for elements and rows:
A = [1 2 3
4 5 6
7 8 9]
This is not save and as soon as operators are inserted, it get amginuous:
[1 2], [1 - 2], [1 -2], [1-2]
The clean way is to write explicitly, what you need:
A = [1, 2, 3; ...
4, 5, 6; ...
7, 8, 9]
B = [1, -2];
1 comentario
Daksh
el 19 de Dic. de 2022
Kindly save your data in .txt or binary files. As for writing your own data, make sure to use proper punctuations between values (like commas, braces) for data clarity and separation, similar to Jan's answer.
Hope it helps!
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!