フィルターのクリア

How to display a matrix in 1 column?

29 ビュー (過去 30 日間)
Nurulhuda Ismail
Nurulhuda Ismail 2019 年 12 月 4 日
コメント済み: Nurulhuda Ismail 2019 年 12 月 4 日
If I have a 3x3 matrix, then I want to display all the elements in 1-column. What I should do is I use a code written like this:
MatrixA =complex(rand(3),rand(3));
yourvector = MatrixA(:);
And the output should be like this:
MatrixA =
0.0368 + 0.8469i 0.4985 + 0.9399i 0.2231 + 0.9552i
0.1905 + 0.4090i 0.4067 + 0.9367i 0.1639 + 0.6461i
0.1353 + 0.6872i 0.2031 + 0.5439i 0.8975 + 0.6536i
yourvector =
0.0368 + 0.8469i
0.1905 + 0.4090i
0.1353 + 0.6872i
0.4985 + 0.9399i
0.4067 + 0.9367i
0.2031 + 0.5439i
0.2231 + 0.9552i
0.1639 + 0.6461i
0.8975 + 0.6536i
However, how am I going to separate the column based on the row?I expect my result should be like this:
0.0368 + 0.8469i
0.1905 + 0.4090i
0.1353 + 0.6872i
0.4985 + 0.9399i
0.4067 + 0.9367i
0.2031 + 0.5439i
0.2231 + 0.9552i
0.1639 + 0.6461i
0.8975 + 0.6536i
Can someone help me? Thank you.

採用された回答

Fangjun Jiang
Fangjun Jiang 2019 年 12 月 4 日
Don't struggle too much. A for-loop will do. Or displaying "column #" would be more helpful when the array size is bigger.
for k=1:size(a,2)
disp(a(:,k));
disp(' ');
end
  3 件のコメント
Fangjun Jiang
Fangjun Jiang 2019 年 12 月 4 日
  1. Notice the difference between "\t" and "\n" in fprintf() in your code
  2. fprintf() won't print complex numbers
  3. Using diary() might give you what you want
diary('MatrixA.txt');
for k=1:size(a,2)
disp(a(:,k));
disp(' ');
end
diary off;
Nurulhuda Ismail
Nurulhuda Ismail 2019 年 12 月 4 日
Thank you...you make my day for today..

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by