How to select the columns of a matrix which are a multiple of 5?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hye
I don't know how to solve the following exercise:
M is a 3x5000 matrix. A student wants to select the elements on the third row in all columns which are a multiple of 5.
The student writes the following script.
N = zeros(1,1000)
for i = 1:5000
if rem(i,5) == 0
N(i/5) = M(3,i);
end
end
I have to simplify it using only N = M(...). How do I do that?
1 comentario
Guillaume
el 9 de En. de 2020
It's hard to give you any help without giving the solution away (which would be cheating).
For which i values would the if be true? Couldn't you pass these values directly as indices of M and not bother with the loop?
Respuestas (2)
Alex Mcaulley
el 9 de En. de 2020
N = M(3,5:5:end)
2 comentarios
Guillaume
el 9 de En. de 2020
In my opinion (as an academic), it'd be better if you didn't post outright solution to homework. Particularly, when it's that easy.
Ver también
Categorías
Más información sobre 2-D and 3-D Plots 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!