Find equal values and their position in a column vector!

4 visualizaciones (últimos 30 días)
Verners Vitkovskis
Verners Vitkovskis el 16 de Dic. de 2019
Respondida: Image Analyst el 16 de Dic. de 2019
I have task in university which asks me to create a vector with randi, which I have done, and find the min value. The second part is that I have to make a loop that goes trough that vector and compares all the values to min value, and if they are equal - display the position of that value.
I've gotten so far:
N = input('Input number ');
V = randi([6,10],N,1)
[value, position] = min(V)

Respuestas (1)

Image Analyst
Image Analyst el 16 de Dic. de 2019
That's not a loop like they specifically asked you to use. And min() only gives you the FIRST index, not all of them. Use for after your existing code:
[rows, columns] = size(V);
for k = col = 1 : columns
for row = 1 : rows
if V(row, col) == value
fprintf(................) % Print out row and col
end
end
end

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by