필터 지우기
필터 지우기

Operands to the || and && operators must be convertible to logical scalar values. Error in logspace (line 23) if d2 == pi || d2 == single(pi)

조회 수: 3 (최근 30일)
i have a vector of current and vector of voltage , i want to get logarithmic samples from both vectors instead of equally spaces. i try current=[...........] voltage=[...........] logspace(current,voltage) it will give me error.

채택된 답변

Iain
Iain 2014년 2월 27일
Assuming that logspace is something you didn't write and you can't change the if statement:
for i = 1:1666
logarithmic_space(i) = logspace(current(i),voltage(i))
end

추가 답변 (2개)

Jos (10584)
Jos (10584) 2014년 2월 25일
Apparantly, one of the expressions d2 == .. is not a logical scalar. My first guess would be that d2 is not a scalar, but an array with more than 1 element. Can you insert a
disp(size(d2))
just before the if statement?
Then, what would you like to do when there are more elements in d2. Compare them all to pi? ALL and ANY may help you out here:
help all
help any
In addition, comparing floating points using == is tricky. Take a look here:
d2 = 0.1+0.2+0.3
if d2==0.6
disp('d2 equals 0.6')
else
disp('d2 does NOT equal 0.6')
end
Not quite what you would expected. The solution to compare two floating point values, is to use a tolerance:
if abs(valueOne - valueTwo) < TOL
...
end
where you can define a tolerance.
  댓글 수: 1
zaid
zaid 2014년 2월 27일
thank you, Wayne King and jos, but my main problem is how can i get logarithmic space from my data that i got it from an experiment . i have current vector of 1666 samples and voltage of same number of samples.so size(current)= 1666 1 and current = 1666 1 i want to get data samples as logarithmic space of current vs voltage.

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


zaid
zaid 2014년 2월 27일
i forgot to tell you this error:
Operands to the and && operators must be convertible to logical scalar values. Error in logspace (line 23) if d2 == pi d2 == single(pi)
is appear when i try to use logspace(current,voltage),but i don't know if logspace is the correct function or not?

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by