How can I reverse the direction of the rows and columns using printmat?

When I use this code:
Depth_of_cut = [1, 2, 3, 4];
Feedrate = [0.1, 0.2, 0.3, 0.4];
Fv = magic(4);
printmat(Fv,'Tangential Force, N', num2str(Depth_of_cut), num2str(Feedrate))
The result will be:
Tangential Force, N =
0.1 0.2 0.3 0.4
1 16.00000 2.00000 3.00000 13.00000
2 5.00000 11.00000 10.00000 8.00000
3 9.00000 7.00000 6.00000 12.00000
4 4.00000 14.00000 15.00000 1.00000
But I want it to be like:
Tangential Force, N =
4 4.00 14.00 15.00 1.00
3 9.00 7.00 6.00 12.00
2 5.00 11.00 10.00 8.00
1 16.00 2.00 3.00 13.00
0.1 0.2 0.3 0.4
So basically I would like to: 1. Reverse the rows to be started from the bottom to the top (The matrix and the rows numbers). 2. Put the columns numbers in the bottom of the table. 3. If there is a way to control the decimal using printmat would be good, otherwise it will be ok.
Thanks a lot,

 Respuesta aceptada

Check out the flipud() function.

3 comentarios

Haitham's Answer moved here:
When I tried flipud on the matrix it works, but with rows names it didn't. Then I tried to use the function flip and it works well. So the code now is:
Depth_of_cut = [1, 2, 3, 4];
Feedrate = [0.1, 0.2, 0.3, 0.4];
Fv = magic(4);
printmat(flipud(Fv),'Tangential Force, N', flip(num2str(Depth_of_cut)), num2str(Feedrate))
And the result is:
Tangential Force, N =
0.1 0.2 0.3 0.4
4 4.00000 14.00000 15.00000 1.00000
3 9.00000 7.00000 6.00000 12.00000
2 5.00000 11.00000 10.00000 8.00000
1 16.00000 2.00000 3.00000 13.00000
Which is good. Now, the columns name, any idea how to place it in the bottom of the table.
Thank you.
What are the column names? If you're printing to the command window, you can simply use fprintf() to print whatever you want:
fprintf('Column 1 Column 2 Column 3 Column 4 Column 5'\n');
The columns names are: 0.1, 0.2, 0.3 and 0.4 which is the Feedrate values. These values should be entered by the user in terms of the number and the values itself, so we do not know how many columns (number of values) and the values itself. Thus, using fprintf function is not an option as the number of the columns are subjected to change.
By the way, the flip function can be used with both, the matrix and the string as:
printmat(flip(Fv),'Tangential Force, N', flip(num2str(Depth_of_cut)), num2str(Feedrate))

Iniciar sesión para comentar.

Más respuestas (1)

Use my function printmapud:
function printmapud(a,name,rlab,clab)
T = evalc('printmat(flipud(a),name,fliplr(rlab),clab);');
C = regexp(T, '\n', 'split');
ind = [1 2 4:numel(C)-2 3 numel(C)-1 numel(C)];
for i = ind
disp(C{i})
end

4 comentarios

it says:
Error using printmat (line 61)
Not enough column labels.
I didn't understand why the error occurs as I have no idea about the functions that you used in the code.
Strange. If I type
printmatud(Fv,'Tangential Force, N', num2str(Depth_of_cut), num2str(Feedrate))
I get
Tangential Force, N =
4 4.00000 14.00000 15.00000 1.00000
3 9.00000 7.00000 6.00000 12.00000
2 5.00000 11.00000 10.00000 8.00000
1 16.00000 2.00000 3.00000 13.00000
0.1 0.2 0.3 0.4
which is exactly what you want...
Haitham
Haitham el 6 de Jul. de 2015
Editada: Haitham el 6 de Jul. de 2015
Oh no! what a mistake! I tried it again and it works well, my mistake, sorry about that. The function works well until 5 columns but when it comes to more than 5 columns it will mess up. Thank you.
Thorsten
Thorsten el 7 de Jul. de 2015
Editada: Thorsten el 7 de Jul. de 2015
Thank you for re-testing my function. Short comment on the why it "messes up", as you call it: For more than 5 columns it "messes up" by inserting a line break, same as printmat.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Types en Centro de ayuda y File Exchange.

Preguntada:

el 2 de Jul. de 2015

Editada:

el 7 de Jul. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by