How can I fix error in fzero (line 241)
Mostra commenti meno recenti
When I use the following fzero function in Matlab R2012a:
for jj=1:358;
mat=cv_o2{jj};
pr=CC_m{jj};
x = [-5 100];
fun = @(x)mat-(std(power(pr,x),1,3)./mean(power(pr,x),3))
b=fzero(fun,x);
BB{jj}=b;
end
end
I get the following error message:
Operands to the || and && operators must be convertible to logical scalar values.
Error in fzero (line 241)
if any(~isfinite([fa fb])) || any(~isreal([fa fb]))
I do not understand what the matter is. Could someone write me how can I fix this error?
Risposte (1)
Titus Edelhofer
il 3 Set 2015
0 voti
Hi,
fzero works for scalar valued functions. Looking at your function I guess it's not scalar valued (i.e., if you call your function fun for one value, the value should not be a vector/matrix but a scalar ("number").
Titus
7 Commenti
Szabó-Takács Beáta
il 3 Set 2015
Titus Edelhofer
il 3 Set 2015
Hi,
what is pr?
- Is it a matrix? Then I don't understand nanmean(pr(i,j).^x,3), because pr(i,j) would be a number, how should one calculate a mean ...
- Or is it a cell array (and pr{i,j} is a 3D matrix)? In this case you need to use pr{i,j} instead of pr(i,j) for both inside nanstd and nanmean ...
Titus
Szabó-Takács Beáta
il 3 Set 2015
Torsten
il 3 Set 2015
All pr(i,j) are greater than zero ? Otherwise there will be a problem to calculate pr(i,j)^x.
Best wishes
Torsten.
Szabó-Takács Beáta
il 3 Set 2015
Titus Edelhofer
il 3 Set 2015
Hi,
but if pr is a 3D matrix, should't it then be pr(i,j,:)?
Titus
Torsten
il 4 Set 2015
pr(i,j) is a scalar. Thus taking nanstd(pr(i,j)^x) gives Inf since you divide by 0.
Best wishes
Torsten.
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!