# how to identify and read positive and negative data from excel?

8 visualizaciones (últimos 30 días)
Vishnuvardhan Naidu Tanga el 27 de Oct. de 2021
Respondida: Mathieu NOE el 27 de Oct. de 2021
Hello all,
I am trying to read excel data which has positive and negative. Is there any way to identify the data. I am currently using the following code to identify it. But is theree any other simple way because i need to analyse other data where the number of cells change. Thanks in advance.
My code:
V = 40.020;
A1 = pi*(X1).^2;
Int1 = trapz(A1, Y1);
A2 = pi*(X2).^2;
Int2 = trapz(A2, Y2);
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

C B el 27 de Oct. de 2021
Editada: C B el 27 de Oct. de 2021
% get data in two columns
col_1 = num(:,1);
col_2 = num(:,2);
% get negative index by col_1<0
Neg_X = col_1(col_1<0);
Neg_Y = col_2(col_1<0);
% get positive index by col_1>=0
POS_X = col_1(col_1>=0);
POS_Y = col_2(col_1>=0);
A1 = pi*(Neg_X).^2;
Int1 = trapz(A1, Neg_Y)
Int1 = 0.5773
A2 = pi*(POS_X).^2;
Int2 = trapz(A2, POS_Y)
Int2 = 0.5789
##### 3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
C B el 27 de Oct. de 2021
Please take look at where 0 should be incuded.
in above code i have added it as positive number.
Vishnuvardhan Naidu Tanga el 27 de Oct. de 2021
Thats fine. I am considering the zero as a positive integer. Thanks once again

Iniciar sesión para comentar.

### Más respuestas (1)

Mathieu NOE el 27 de Oct. de 2021
Hello
try this - it also only need one call to readxls
X = data(:,1);
Y = data(:,2);
X1 = X(X<0);
X2 = X(X>=0);
Y1 = Y(X<0);
Y2 = Y(X>=0);
V = 40.020;
A1 = pi*(X1).^2;
Int1 = trapz(A1, Y1)
A2 = pi*(X2).^2;
Int2 = trapz(A2, Y2)
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Data Import from MATLAB 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!

Translated by