I want to sum the loop result which the result is indicates the total of selected input
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Muhamad Zulfikre Norsid
el 27 de Oct. de 2015
Comentada: Muhamad Zulfikre Norsid
el 27 de Oct. de 2015
disp('Please vote for your candidates'); a=1; b=2; c=3; d=4;
for y=1:5
x=input('your candidates= ')
end
w = sum(a)
x = sum(b)
y = sum(c)
z = sum(d)
0 comentarios
Respuesta aceptada
Wanbin Song
el 27 de Oct. de 2015
You can code it as belows:
disp('Please vote for your candidates'); a=1; b=2; c=3; d=4;
result = [];
for y=1:5
x = input('your candidates= ');
result = [result x];
end
w = nnz(result == a)
x = nnz(result == b)
y = nnz(result == c)
z = nnz(result == d)
Using vector concatenation and nnz(number of non-zero) function.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!