Multiplying elements of a vector
Mostrar comentarios más antiguos
I'm creating a function to find areas of shapes. It takes two inputs, the first is a vector and the second is a variable number.
function area = area_calculator(A, num)
switch num
case 1 % Circle
r = norm(A);
A = pi*r^2 % Area
case 2 % Rectangle
A = b*h % Area; I want to multiply vector element 1 by vector element 2
end
So if I give it
>> area_calculator([2,4], 2)
I'm wanting b*h to be 2*4
I'm unsure how to instruct matlab to perform multiplication within the vector
Thank you very much
Respuesta aceptada
Más respuestas (1)
per isakson
el 28 de Jun. de 2020
Replace
case num == 1
by
case 1
1 comentario
Stephen Warren
el 28 de Jun. de 2020
Categorías
Más información sobre Calendar en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!