how can i convert c code c code to Mat lab code?

#include<stdio.h>
#include<math.h>
int main(){
float x1,y1,x2,y2,vx,vy,len,x3,y3,size;
vx=x1-x2;
vy=y1-y2;
len=sqrt((vx*vx)+(vy*vy));
x3=vx/((len*size)+x1);
y3=vy/((len*size)+y1);
float temp1,temp2,angle;
temp1=y3-y1;
temp2=x3-x1;
angle=atan2(temp1,temp2)+1.57;
return 0;
}

4 件のコメント

KSSV
KSSV 2019 年 3 月 27 日
編集済み: KSSV 2019 年 3 月 27 日
What attempt you made to convert this simple c function to MATLAB?
Anusuya Rajendran
Anusuya Rajendran 2019 年 3 月 27 日
I don't know how to code in matlab
Adam
Adam 2019 年 3 月 27 日
You need to learn Matlab in that case! There are links to tutorials from the Mathworks website. If you don't knnow how to code Matlab it wouldn't be all that helpful even if someone just does your work for you and converts that one function into Matlab if you have no idea what to do with it anyway.
Image Analyst
Image Analyst 2019 年 4 月 1 日

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2019 年 3 月 27 日

0 投票

This is an invalid C code. You use e.g. x1, x2, size, without defining it. It is meaningless to post the conversion of invalid C code to invalid Matlab code. But if you really want to fail in another language:
vx=x1-x2;
vy=y1-y2;
len=sqrt((vx*vx)+(vy*vy));
x3=vx/((len*size)+x1);
y3=vy/((len*size)+y1);
temp1=y3-y1;
temp2=x3-x1;
angle=atan2(temp1,temp2)+1.57;
That's it - a 1-by-1 copy. Not working also.

2 件のコメント

Walter Roberson
Walter Roberson 2019 年 4 月 1 日
You would probably want to replace the 1.57 with pi/2
Walter Roberson
Walter Roberson 2019 年 4 月 1 日
The code Jan posted is likely not exactly the same as the C code.
The C code uses float for variables. In C, float refers to single precision numbers. MATLAB typically uses double precision instead. To match the C, the code would probably have to deliberately use single() on each input parameters, to force what is likely to be a double precision input to instead use single precision.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2019 年 3 月 27 日

コメント済み:

2019 年 4 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by