Running a function of 2 variables

1 view (last 30 days)
I am having trouble running this command:
cr = [0:.1:1];
cr = logical(cr);
wn = [0:.1:1];
wn = logical(wn);
amp(cr,wn) = sqrt(1-2.*cr.*(1-cos(pi.*wn)).*(1-cr))
I get this error:
Subscripted assignment dimension mismatch.
Error in FundamentalsHW4 (line 6) amp(cr,wn) = sqrt(1-2.*cr.*(1-cos(pi.*wn)).*(1-cr))
Any help?
  1 Comment
Guillaume
Guillaume on 17 Oct 2014
The best way for you to find what is wrong is to step through your code with the debugger.
Your code makes no sense, and you would have seen that immediately if you'd gone through the debugger. Why are you converting cr and wn to logical? Both of them end up as an array of 0 and 1 with only the first element as 0.
If you need more help, you would be better off explaining what you are trying to do rather than asking us to correct code that may not even be the solution to what you want.

Sign in to comment.

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 17 Oct 2014
cr = [0:.1:1];
wn = [0:.1:1];
f=@(cr,wn) sqrt(1-2.*cr.*(1-cos(pi.*wn)).*(1-cr))
amp=bsxfun(f,cr',wn)
I think that's what you want to do.

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!