make column in a matrix: 1,1,1,2,2,2,3,3,3 etc
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Andrea
el 20 de Nov. de 2012
Comentada: Gal
el 15 de Oct. de 2015
Hi,
I'm trying to create a matrix A(21,4). In the second column I want to insert the numbers 1,1,1,2,2,2,3,3,3 etc until the end of the column. Tried this:
A = zeros(21, 4);
A(:,2) = rem((0:size(imageInformation,1)-1)',7)+1;
Which creates the column 1,2,3,4,6,7,1,2,3 etc. How can I modify this/is there any way to write code which would input the previously mentioned numbers into the matrix?
1 comentario
Respuesta aceptada
Más respuestas (5)
Image Analyst
el 20 de Nov. de 2012
Editada: Image Analyst
el 20 de Nov. de 2012
Try this:
A(:, 2) = [1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7]';
If you need it more general, then say so.
If you have the Image Processing Toolbox, you can do it more generally this way:
A = zeros(21,4);
[rows columns] = size(A);
secondColumn = imresize((1:rows/3)', [rows, 1], 'nearest')
A(:, 2) = secondColumn
0 comentarios
Wayne King
el 20 de Nov. de 2012
One of many ways (requires Signal Processing Toolbox for upsample.m)
x = (1:7)';
x = repmat(x,1,4);
A = upsample(x,3);
A = filter(ones(3,1),1,A);
0 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB 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!