Can somebody tell me what is wrong with the following code?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Matt Fig
el 17 de Dic. de 2012
It helps to read the Getting Started section of the doc before jumping in like this. You need to understand basic syntax.
Respuesta aceptada
Más respuestas (1)
John Petersen
el 17 de Dic. de 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;
2 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!