Can somebody tell me what is wrong with the following code?
2 views (last 30 days)
Show older comments
Hi,
I wrote the following function to build an array of numbers(in the range of 65...74), representing the digits of a number. Here's the algorithm:
function [ y ] = fcn( u )
var y:array[1..10] of byte;
u: longint;
i,nr:byte;
s:boolean;
begin
newu=0;
nr=0;
s=false;
if u<0 then s=true;
while u~=0 do
begin
newu=newu*10+mod(u,10);
u=(u/10);
inc(nr);
end;
for i=nr:1 do
begin
y(i)=mod(newu,10);
newu=(newu/10);
end;
for i=1:nr do
begin
if y(i)==0 then y(i)=65;
if y(i)==1 then y(i)=66;
if y(i)==2 then y(i)=67;
if y(i)==3 then y(i)=68;
if y(i)==4 then y(i)=69;
if y(i)==5 then y(i)=70;
if y(i)==6 then y(i)=71; //At least one END is missing: the statement may begin here.
if y(i)==7 then y(i)=72;
if y(i)==8 then y(i)=73;
if y(i)==9 then y(i)=74;
end
end
y=u;
end
And Matlab gives me the error message stated after the 2 slashes...I am a beginner in Matlab, i can only write code in Pascal language, so I would be glad if someone helped me out.
Thank you, Zoli
1 Comment
Matt Fig
on 17 Dec 2012
It helps to read the Getting Started section of the doc before jumping in like this. You need to understand basic syntax.
Accepted Answer
More Answers (1)
John Petersen
on 17 Dec 2012
You're syntax is incorrect for Matlab code. First, you don't need to declare your variables. Take out the do's, begin's, and then's. You need an end after every if statement. Comments begin with %, not //. The last for loop can be simplified to
y = y + 65;
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!