MATLAB Small matlab code not working. Why ?

AI Thread Summary
The discussion centers around a MATLAB code snippet that generates an error indicating that 'mubeton' is treated as a function rather than a vector. The user seeks clarification on why this is happening, especially since they are trying to access the first element of the vector using 'mubeton(1)'. Suggestions from other participants include breaking down lengthy lines of code into smaller, more manageable segments to avoid interpreter issues, and performing a 'clear all' command to reset the workspace. Ultimately, the user successfully resolves the issue by rewriting the code with intermediate calculations, which eliminates the error.
imsolost
Messages
18
Reaction score
1
Code is the following :
Matlab:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xiter=[0.7 20 10];
mubeton=[0.100 0.80 0.70 0.60 0.50 0.25];
muair=[0.05 0.042 0.04 0.032 0.021 0.011];
zl=[5 30 70 100];

fnorm1 = @(d,a0,dmax) (a0*(1-exp(-(0.5*log(d./dmax)).^2))+exp(-(0.5*log(d./dmax)).^2));
fnorm2 = @(d,dmax,DRL) exp(-(d-dmax)./DRL);
integ=integral(@(r)((r<xiter(2)).*fnorm1(r,xiter(1),xiter(2))+(r>=xiter(2)).*fnorm2(r,xiter(2),xiter(3))),0,inf); %xiter manquant en input
funny=@(r,xiter)((r<xiter(2)).*fnorm1(r,xiter(1),xiter(2))+(r>=xiter(2)).*fnorm2(r,xiter(2),xiter(3)))./integ;

eps=@(r)(integral2(@(R,phi)(exp(-mubeton(1).*(sqrt((zl(1)+r).*(zl(1)+r) + R.*R) - zl(1).*sqrt((zl(1)+r).*(zl(1)+r) + R.*R)./(zl(1)+r))-muair(1).*(zl(1).*sqrt((zl(1)+r).*(zl(1)+r) + R.*R)./(zl(1)+r))).*R./(2.*sqrt(R.*R+(zl(1)+r).*(zl(z1)+r)))),0,inf,0,2*pi));
%produit=@(y)((eps(y)).*((funny(y,[0.7 20 10]))));
integral(@(y)((eps(y)).*((funny(y,[0.7 20 10])))),0,inf,'ArrayValued',true)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error is the following :

"Undefined function 'mubeton' for input arguments of type 'double'."

Why the hell MATLAB thinks this is a function wile its clearly expressed as a vector ?

Thx for any help guys :)
 
Last edited by a moderator:
Physics news on Phys.org
Perhaps because you have "mubeton(1)"?
 
Thank you for your answer but i don't get what you mean. I want indeed to use the first value stored in the vector mubeton. So mubeton(1) seems right to me.
 
Sorry, I made a rushed suggestion on my way out the door without looking at your code properly so please disregard my answer.
 
The line where mubeton(1) is used is awfully long. Have you tried to break that up into multiple lines of smaller intermediate results? Thinking an interpreter weirdness. [EDIT: not likely. Have you tried a clear all?] Also this is not the whole code, so I can't reproduce your error message.
 
Last edited:
  • Like
Likes FactChecker
I suggest breaking that huge line defining eps into several "baby-step" intermediate calculations on separate lines. Error messages are no always exact about the error location.
Before that bunch of smaller lines, set temp1 = mubeton(1) and see if it accepts it.

PS. I don't have MATLAB so I can't give specific help.
 
lewando said:
The line where mubeton(1) is used is awfully long. Have you tried to break that up into multiple lines of smaller intermediate results? Thinking an interpreter weirdness. [EDIT: not likely. Have you tried a clear all?] Also this is not the whole code, so I can't reproduce your error message.

I followed your suggestion and rewrote the code with more intermediate calculation subfunctions. It worked since problem seems to be gone.

Thank you all guys for this help.
 
  • Like
Likes FactChecker

Similar threads

Replies
4
Views
1K
Replies
2
Views
3K
Replies
2
Views
2K
Replies
3
Views
3K
Replies
18
Views
4K
Replies
8
Views
2K
Back
Top