Use array functions, logical, and relational operators.

1 visualización (últimos 30 días)
Vagner Ribeiro
Vagner Ribeiro el 30 de Nov. de 2016
Respondida: Vishal Neelagiri el 5 de Dic. de 2016
Calculate the percentage of points in the positive quadrant. Assign this to the variable p. The positive quadrant is defined by having both coordinates positive. A percentage is equal to 100 times a fraction. The value should be close to 25%.
I am having a hard time with this. please help

Respuestas (1)

Vishal Neelagiri
Vishal Neelagiri el 5 de Dic. de 2016
Let us assume that you have a variable named 'data' that is an n*2 matrix where 'n' corresponds to the total number of points and the x,y coordinates of these n points are provided in their respective 2 columns. You can use the following code in order to calculate the percentage of points in the positive quadrant, store this value in 'p' and then check if this value is equal to 25:
a = 0;
for i=1:n
if (data(i,1)>0)
if (data(i,2)>0)
a = a + 1;
end
end
end
p = (a/n)*100;
if (p==25)
disp('25% of all points are in first quadrant')
end

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by