Borrar filtros
Borrar filtros

how do i change a matrix dimension from MxN to 100xN?

1 visualización (últimos 30 días)
Ganeshkumar M
Ganeshkumar M el 28 de Jun. de 2016
Editada: James Tursa el 20 de Sept. de 2023
Hi i have a matrix of size 46 x 1123 and i would want to expand it to a dimension of 100 x 1123. It will be best if the additional element rows are a copy of the original matrix as i will be using classify for subsequent manipulations.
Will be running this as a script hence the number of rows of 46 will differ from file to file but would want to standardise the output number of rows to 100. Thank you!
  1 comentario
Image Analyst
Image Analyst el 28 de Jun. de 2016
The 54 rows to tack on are not a multiple of 46 so exactly how were you planning on filling those rows? What rows from the original 46 are to be copied into the 54 new rows? And do you want to insert the rows at the top, or bottom or both? Have you read this link yet?

Iniciar sesión para comentar.

Respuesta aceptada

Jennifer Rebbin
Jennifer Rebbin el 20 de Sept. de 2023
Starting in R2023b, you can use the paddata function to pad data by adding elements. For example, specify the size of the padded data and the pattern for adding elements.
A = rand(46,1123);
B = paddata(A,[100 size(A,2)],Pattern="circular")
B = 100×1123
0.7436 0.5438 0.6660 0.1121 0.7842 0.8639 0.7133 0.6494 0.7917 0.4459 0.2734 0.6866 0.9340 0.9326 0.3143 0.8821 0.8909 0.6626 0.5976 0.4129 0.8291 0.6725 0.5188 0.3823 0.6394 0.7858 0.9217 0.7838 0.0021 0.6309 0.6387 0.8029 0.3931 0.8646 0.9986 0.2212 0.8457 0.7107 0.4091 0.5239 0.4301 0.6880 0.0673 0.7332 0.5872 0.1162 0.9441 0.3966 0.0320 0.2972 0.0588 0.0631 0.8817 0.1696 0.5486 0.9976 0.9094 0.0196 0.8032 0.0822 0.4330 0.5467 0.9516 0.8639 0.8572 0.2011 0.3898 0.2644 0.1783 0.3132 0.3309 0.1292 0.5893 0.8217 0.0845 0.1998 0.5685 0.6710 0.4581 0.1210 0.9573 0.2766 0.7137 0.0821 0.1991 0.9659 0.5574 0.3693 0.9533 0.1005 0.9608 0.9600 0.7722 0.1067 0.0133 0.2275 0.8695 0.0397 0.9013 0.7071 0.3495 0.8918 0.2570 0.7546 0.9958 0.6629 0.8288 0.6546 0.5034 0.0321 0.4833 0.3891 0.0992 0.1082 0.7810 0.2339 0.7847 0.3233 0.5024 0.3656 0.1199 0.7941 0.6164 0.7367 0.5058 0.0124 0.4026 0.3437 0.4312 0.4766 0.1198 0.7214 0.6549 0.2575 0.6488 0.5384 0.0060 0.6125 0.3784 0.7593 0.7914 0.2200 0.0749 0.7851 0.6768 0.7088 0.2420 0.9198 0.4737 0.7957 0.2158 0.5813 0.5044 0.9975 0.8615 0.0455 0.9029 0.4383 0.1660 0.4871 0.4419 0.8479 0.8815 0.0080 0.3903 0.4571 0.1074 0.1627 0.1358 0.5590 0.5390 0.0150 0.5463 0.0913 0.0106 0.5635 0.6914 0.0852 0.1883 0.1529 0.6307 0.7918 0.3002 0.3918 0.1373 0.1741 0.0451 0.7172 0.7828 0.6503 0.2226 0.3355 0.5721 0.3885 0.9841 0.9496 0.7608 0.4049 0.4759 0.8322 0.6123 0.7332 0.0504 0.7847 0.4255 0.0395 0.9247 0.1503 0.4191 0.5201 0.8332 0.7596 0.5248 0.5652 0.4841 0.8220 0.2611 0.7814 0.6772 0.8645 0.0204 0.2837 0.7655 0.9466 0.3531 0.9169 0.3446 0.9515 0.8798 0.2513 0.0554 0.3383 0.1919 0.1318 0.7853 0.4938 0.9404 0.7281 0.3607 0.4882 0.6721 0.9637 0.3519 0.5964 0.7033 0.7213 0.3993 0.4608 0.6702 0.3157 0.8124 0.4468 0.6967 0.1585 0.0855 0.2563 0.8770 0.7103 0.8554 0.9224 0.0440 0.9387 0.5826 0.5577 0.8055 0.1654 0.3831 0.0689 0.4387 0.5844 0.1070 0.8135 0.6891 0.0283 0.7952 0.1752 0.2419 0.9424 0.2925 0.6621 0.6275 0.8718 0.6960 0.0905 0.9735 0.3709 0.4177 0.1207 0.6486 0.6895 0.2079 0.3973 0.9248 0.8499 0.0851 0.4868 0.0618 0.5676 0.9688 0.6856

Más respuestas (1)

the cyclist
the cyclist el 28 de Jun. de 2016
I have the same questions as Image Analyst asked, but here is my best guess as to what you want:
% Original matrix
A = rand(46,1123);
% New matrix
newRowCount = 100;
[m,n] = size(A);
B = zeros(newRowCount,n);
B = A(mod((1:newRowCount)-1,m)+1,:);
It fills in B from A row-by-row, repeating from the top of A if it reaches the bottom.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by