How to display a matrix in 1 column?

33 visualizaciones (últimos 30 días)
Nurulhuda Ismail
Nurulhuda Ismail el 4 de Dic. de 2019
Comentada: Nurulhuda Ismail el 4 de Dic. de 2019
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.

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 4 de Dic. de 2019
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 comentarios
Fangjun Jiang
Fangjun Jiang el 4 de Dic. de 2019
  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 el 4 de Dic. de 2019
Thank you...you make my day for today..

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Text Data Preparation 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!

Translated by