MATLAB Answers

Using fprintf to save a matrix changes the order of my matrix

5 ビュー (過去 30 日間)
Bruno Carvalho
Bruno Carvalho 2021 年 6 月 7 日
コメント済み: Bruno Carvalho 2021 年 6 月 7 日
I dont understand why, when i use the fprintf function my matrix changes from the orange example to the blue one, can someone please help?

回答 (2 件)

Julius Muschaweck
Julius Muschaweck 2021 年 6 月 7 日
Your matrix does not change. You are outputting the values in your matrix, six numbers per line, as it is stored internally. And in Matlab, storage is "column major". Try your code in line 17, replacing teste with its transpose, teste' and you will get the desired output.
  1 件のコメント
Bruno Carvalho
Bruno Carvalho 2021 年 6 月 7 日
Yes, it worked. Now i understand, thank you very much.

サインインしてコメントする。


James Tursa
James Tursa 2021 年 6 月 7 日
編集済み: James Tursa 2021 年 6 月 7 日
MATLAB stores 2D matrices in column order. That is, the numbers in your matrix are stored in memory in this order:
0, 1, 2, 3, 2.0151e9, ... etc.
So when you print the matrix out, it simply prints out the numbers as they are stored in memory. If you want it to print like it displays on the screen in MATLAB, print out the transpose. E.g.,
fprintf( whatever , teste.');
  1 件のコメント
Bruno Carvalho
Bruno Carvalho 2021 年 6 月 7 日
Yes, it worked, thank you very much

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by