필터 지우기
필터 지우기

Can somebody tell me what is wrong with the following code?

조회 수: 1 (최근 30일)
Zoltan
Zoltan 2012년 12월 17일
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
Matt Fig
Matt Fig 2012년 12월 17일
It helps to read the Getting Started section of the doc before jumping in like this. You need to understand basic syntax.

댓글을 달려면 로그인하십시오.

채택된 답변

Pedro Villena
Pedro Villena 2012년 12월 17일
num2str(u)
doc num2str

추가 답변 (1개)

John Petersen
John Petersen 2012년 12월 17일
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
Zoltan
Zoltan 2012년 12월 17일
Thank you for the advice
Zoltan
Zoltan 2012년 12월 17일
I rewrote the code. I want to use this as an embedded function in simulink. Everything is OK, except it doesn't wanna use the 'mod' function with the input value(u), because its class is embedded.fi. How can i resolve this problem? Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by