I already have a row matrix, how to change it's dimensions to 5x5 for example?

3 visualizaciones (últimos 30 días)
So this is how it is right now. My matrix A = num(idx) is a row matrix. How can I change it's dimensions to 5x5?
  2 comentarios
Matt J
Matt J el 26 de Abr. de 2021
Editada: Matt J el 26 de Abr. de 2021
Please post code in code wells llike below, rather than as screenshots.
num=1:100;
A=num(isprime(num))
A = 1×25
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Aside from that, your matrix contains only 25 elements, so how would you populate the other 75 elements of a 10x10 matrix?
Francisco Boudagh
Francisco Boudagh el 26 de Abr. de 2021
Right, but lets edit and say 25 numbers. How to make 5x5 matrix of that (instead of row matrix)?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Abr. de 2021
It looks like you are not being asked to draw the primes between 1 and 100; it looks like you are asked to draw the first 100 primes.
num = 1:600;
idx = isprime(num);
A = num(idx);
if length(A) > 100; A = A(1:100); end
A = reshape(A, 10, 10);
imagesc(A)
colorbar
axis equal tight;
A(end)
ans = 541
However, there is a completely different possibility:
num = reshape(1 : 100, 10, 10);
idx = isprime(num);
imagesc(idx)

Más respuestas (0)

Categorías

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

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by