how to identify and read positive and negative data from excel?
3 次查看(过去 30 天)
显示 更早的评论
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:
X1 = xlsread('Abb73at100.xlsx','A1:A63');
Y1 = xlsread('Abb73at100.xlsx','B1:B63');
V = 40.020;
A1 = pi*(X1).^2;
Int1 = trapz(A1, Y1);
X2 = xlsread('Abb73at100.xlsx','A64:A130');
Y2 = xlsread('Abb73at100.xlsx','B64:B130');
A2 = pi*(X2).^2;
Int2 = trapz(A2, Y2);
0 个评论
采纳的回答
C B
2021-10-27
编辑:C B
2021-10-27
[num data raw] = xlsread('Abb73at100.xlsx');
% 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)
A2 = pi*(POS_X).^2;
Int2 = trapz(A2, POS_Y)
3 个评论
C B
2021-10-27
Please take look at where 0 should be incuded.
in above code i have added it as positive number.
更多回答(1 个)
Mathieu NOE
2021-10-27
Hello
try this - it also only need one call to readxls
data = xlsread('Abb73at100.xlsx');
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!