f

some problems of codes of MATLAB 7.0 working on MATLAB 6.5

```I have used MATLAB for few hours.So I don't know the differences
between version 6.5 and 7.0.I want to use some codes of MATLAB 7.0,
but they doesn't work in MATLAB 6.5.How to change these codes so that
they can work in matlab 6.5.Waiting for your help. Thank you .
The codes are like this .I think changing  the function findPI  may
work ,but I don'y know how

% PIfun.m
% Evaluate a function used to find the PI-line, using Kyle Champley's
% method.
%
% last update: 5/18/06

function y = PIfun(r,R,h,gamma,x3,sb)

temp = R - r*cos(gamma-sb);
y = h*((pi - 2*atan(r*sin(gamma-sb)/temp))*(1 + (r^2 - R^2)/
(2*R*temp)) ...
+ sb) - x3;

% find_PI_Line.m
%
% Find the the parametric interval corresponding to the unique PI-line
% passing through the point x for a given helical pitch.
% This code implements the method of Kyle Champley.
% inputs: P = pitch (cm/turn), R = helix radius, delta_s = s stepsize,
x
% output: PI = [sb st]
%
% last update: 5/18/06

function [PI] = findPI(P,R,delta_s,x)

h = P/(2*pi);
r = sqrt(x(1)^2+x(2)^2);
gamma = atan2(x(2),x(1));

options = optimset('TolX',h*delta_s/100,'FunValCheck','on');

[sb,fval,exitflag] = fzero(@(sb)  PIfun(r,R,h,gamma,x(3),sb),...
[(x(3)-h*pi)/h,x(3)/h],options);

if exitflag ~=1,
disp('Error: PI invalid');
end

% note that beta=sb in Kyle's formula
alphaX = atan(r*sin(gamma-sb)/(R - r*cos(gamma-sb)));
st = sb + pi - 2*alphaX;
PI = [sb st];

```
 0
sokitty (4)
6/21/2007 2:16:36 AM
comp.soft-sys.matlab 211264 articles. 26 followers. lunamoonmoon (257) is leader.

5 Replies
3584 Views

Similar Articles

[PageSpeed] 56

```Where exactly are you having a problem? Is there a compilation error?
At which line? I am assuming you tested it in Matlab 7, and it works
fine?

```
 0
skt (274)
6/21/2007 3:50:43 AM
```On 6 21 ,   11 50 , Srikanth <s...@xdtech.com> wrote:
> Where exactly are you having a problem? Is there a compilation error?
> At which line? I am assuming you tested it in Matlab 7, and it works
> fine?

You konw I want it to work in Matlab 6.5 not Matlab7 but it doesn't
I have called this function :
PI(i,j,k,:) = findPI(P,R,delta_s,[x(i) y(j) z(k)]);
I get this
??? Error: File: C:\MATLAB6p5\work\fbp\findPI.m Line: 20 Column: 29
"identifier" expected, "(" found.

Error in ==> C:\MATLAB6p5\work\fbp\flat_plain.m
On line 362  ==>              PI(i,j,k,:) = findPI(P,R,delta_s,[x(i)
y(j) z(k)]);

```
 0
sokitty (4)
6/21/2007 4:45:15 AM
```Hi
Are you sure this worked under Matlab 7? Because this kind of error is
often something wrong in your code, not something because of a change
in matlab... In the line 362, there is a problem at function call. Try
making a test program, and pass values instead of variables, to see if
your function works. If it does, there is something wrong in the way
you are calling it. If you still get an error, check your function...

```
 0
skt (274)
6/21/2007 6:11:31 AM
```<sokitty@sina.com> wrote in message
>I have used MATLAB for few hours.So I don't know the differences
> between version 6.5 and 7.0.I want to use some codes of MATLAB 7.0,
> but they doesn't work in MATLAB 6.5.How to change these codes so that
> they can work in matlab 6.5.Waiting for your help. Thank you .
> The codes are like this .I think changing  the function findPI  may
> work ,but I don'y know how

*snip*

> [sb,fval,exitflag] = fzero(@(sb)  PIfun(r,R,h,gamma,x(3),sb),...
>                        [(x(3)-h*pi)/h,x(3)/h],options);

Anonymous functions, as this code uses, were introduced in MATLAB 7.0 (R14).
They were not available in MATLAB 6.5 (R13), so you cannot use them in that
version of MATLAB.  You will need to rewrite this code to use a regular
function handle or an inline function with the P1, P2 syntax given in HELP

http://www.mathworks.com/support/solutions/data/1-19HM6.html?solution=1-19HM6

The first half of the Solution section deals with MATLAB 7.0 (R14) and
later; the second half deals with versions of MATLAB prior to 7.0.

I very briefly scanned the code, but I didn't see anything else that looked
like it obviously wouldn't work in MATLAB 6.5.  That doesn't mean there
aren't any, though.

--
Steve Lord
slord@mathworks.com

```
 0
slord (13689)
6/21/2007 2:04:39 PM
```On 6 21 ,   10 04 , "Steven Lord" <s...@mathworks.com> wrote:
> <soki...@sina.com> wrote in message
>
>
> >I have used MATLAB for few hours.So I don't know the differences
> > between version 6.5 and 7.0.I want to use some codes of MATLAB 7.0,
> > but they doesn't work in MATLAB 6.5.How to change these codes so that
> > they can work in matlab 6.5.Waiting for your help. Thank you .
> > The codes are like this .I think changing  the function findPI  may
> > work ,but I don'y know how
>
> *snip*
>
> > [sb,fval,exitflag] = fzero(@(sb)  PIfun(r,R,h,gamma,x(3),sb),...
> >                        [(x(3)-h*pi)/h,x(3)/h],options);
>
> Anonymous functions, as this code uses, were introduced in MATLAB 7.0 (R14).
> They were not available in MATLAB 6.5 (R13), so you cannot use them in that
> version of MATLAB.  You will need to rewrite this code to use a regular
> function handle or an inline function with the P1, P2 syntax given in HELP
>
> http://www.mathworks.com/support/solutions/data/1-19HM6.html?solution...
>
> The first half of the Solution section deals with MATLAB 7.0 (R14) and
> later; the second half deals with versions of MATLAB prior to 7.0.
>
> I very briefly scanned the code, but I didn't see anything else that looked
> like it obviously wouldn't work in MATLAB 6.5.  That doesn't mean there
> aren't any, though.
>
> --
> Steve Lord
> s...@mathworks.com

Hi
Thank you very much .
I will have a try .

```
 0
sokitty (4)
6/22/2007 1:37:07 AM