Hi,
The attached files contains two columns: the first contains voltage data, while the second current data. I would like to select only those current data whose potential is -1.70007 or -1.7001, depending on the rounding of the value. I am trying like this, but it never enters in the first condition loop, even if I know there are some values with V=-1.7001.
Thank you fo your time
Francesca
clear all
load Zn1.txt
Zn1_data=Zn1;
V_Zn1=Zn1_data(:,1);
A_Zn1=Zn1_data(:,2);
for i=1,length(V_Zn1)
if V_Zn1(i)==-1.7001
AA_Zn1(i)=A_Zn1(i);
else
AA_Zn1(i)=0;
end
end

 채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 19일
편집: KALYAN ACHARJYA 2019년 11월 19일

0 개 추천

load Zn1.txt
Zn1_data=Zn1;
V_Zn1=Zn1_data(:,1);
A_Zn1=Zn1_data(:,2);
AA_Zn1(find(V_Zn1~=-1.7001))=0;
Is This?
"I would like to select only those current data whose potential is -1.70007 or -1.7001"
Edited:
load Zn1.txt
Zn1_data=Zn1;
V_Zn1=Zn1_data(:,1);
A_Zn1=Zn1_data(:,2);
idx=(find(V_Zn1==-1.7007 | V_Zn1==-1.7001));
A_new_data=A_Zn1(idx);
A_new_data

댓글 수: 6

Actually, I don't want to set it to 0, but I want to save in the new array the corresponding current value from A_Zn1
I have added another answer, please check.
Ok I think we are on the right way, but when I try to run it an error occurs:
Operands to the || and && operators must be convertible to logical scalar values.
Error in pot_selection (line 19)
idx=(find(V_Zn1==-1.7007 || V_Zn1==-1.7001));
idx=(find(V_Zn1==-1.7007 | V_Zn1==-1.7001));
Ok the script runs but I got :
A_new_data =
0×1 empty double column vector
I think that could be a problem for the value I am using. Actually I know that in my data there is -1.70007 but matlab converts it to -1.7001, so that why I tried with this value. But maybe it is not the one anyway.
Thank you for you answer
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 19일
편집: KALYAN ACHARJYA 2019년 11월 19일
Please note on floating points number and here Read the @Stevan's Answer also (Just below). Please check with other known non decimal numbers, any issue let me know?

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

David Hill
David Hill 2019년 11월 19일

0 개 추천

AA_Zn1=Zn1_data(:,1).*(Zn1_data(:,1)==-1.7001|Zn1_data(:,1)==-1.70007);

댓글 수: 2

I am actually looking for the current data (A_Zn1) corresponding to that value of voltage (V_Zn1=-1.0007)
A_Zn1(V_Zn1==-1.7001|V_Zn1==-1.7007);

댓글을 달려면 로그인하십시오.

Steven Lord
Steven Lord 2019년 11월 19일

0 개 추천

What you're seeing is the first example in the "Avoiding Common Problems with Floating-Point Arithmetic" section on this documentation page. Be very, very careful when using == (which performs exact, down-to-the-last-bit comparison) on floating point numbers. Use a tolerance or use ismembertol.
a = 0:0.1:1;
% ==
a == 0.3 % all elements are false
a(4) - 0.3 % small but not EXACTLY zero
% Tolerance -- eps is "close enough" in this case
abs(a-0.3) < eps % one element is true, the rest are false
% Ismembertol
ismembertol(a, 0.3) % one element is true, the rest are false

카테고리

도움말 센터File Exchange에서 Phased Array System Toolbox에 대해 자세히 알아보기

질문:

2019년 11월 19일

편집:

2019년 11월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by