For large arrays, Matrix rows carry onto next line theyre written in from a fortran program
조회 수: 45 (최근 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!