For large arrays, Matrix rows carry onto next line theyre written in from a fortran program
42 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jan
2022-4-4
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 个评论
Daksh
2022-12-19
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!