フィルターのクリア

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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by