some problems of codes of MATLAB 7.0 working on MATLAB 6.5

some problems of codes of MATLAB 7.0 working on MATLAB 6.5

Post by sokitt » Fri, 22 Jun 2007 11:16:36


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.
%
% Adam Wunderlich
% 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]
%
% Adam Wunderlich
% 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];
 
 
 

some problems of codes of MATLAB 7.0 working on MATLAB 6.5

Post by Srikant » Fri, 22 Jun 2007 12:50:43

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?

 
 
 

some problems of codes of MATLAB 7.0 working on MATLAB 6.5

Post by sokitt » Fri, 22 Jun 2007 13:45:15


thanks for your answer
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)]);
 
 
 

some problems of codes of MATLAB 7.0 working on MATLAB 6.5

Post by Srikant » Fri, 22 Jun 2007 15:11:31

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...
 
 
 

some problems of codes of MATLAB 7.0 working on MATLAB 6.5

Post by Steven Lor » Fri, 22 Jun 2007 23:04:39


*snip*


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
FZERO. This document will also help you modify the code:

http://www.yqcomputer.com/

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
XXXX@XXXXX.COM
 
 
 

some problems of codes of MATLAB 7.0 working on MATLAB 6.5

Post by sokitt » Sat, 23 Jun 2007 10:37:07


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