# Are you convert matlab code to visual basic code form for me, please?

13 ビュー (過去 30 日間)
bek 2011 年 12 月 11 日
Hi, I need your help to translate the matlab code in visual code. I'm new on this subject, and the conversion is very important to me. Thank you in advance, Waiting for your help. Matlab Code is here;
clc,clear all
x = 0:0.2:1; % get a dimensional array of real number type
fid = fopen('dene3.txt','w';); % Please write description
for i=1:6
end
fid = fopen('dene4.txt','w'); % Please write description
for i=1:6
end
clc,clear all
ax=zeros(1,6);
fid = fopen('dene3.txt'); % Please write description
for i=1:6
ay=zeros(1,6);
fid = fopen('dene4.txt');
for i=1:6
ay(i)=fscanf(fid,'%d',1)
end
fclose(fid);

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

### 回答 (3 件)

Paulo Silva 2011 年 12 月 11 日
clc,clear all
x = 0:0.2:1; % get a dimensional array of real number type
fid = fopen('dene3.txt','w';); % open the file for writing
for i=1:6
fprintf(fid,'%8.5f\n',1.87*x(i)); % print value 1.87*x(i) to the file and go to the start of the next line, data is fixed point notation, precision is 5 and field width is 8
end
fclose(fid); % close the open file
fid = fopen('dene4.txt','w'); % open the file for writing
for i=1:6
fprintf(fid,'%7d\n',12*i); % print value of 12*i to the file and go to the start of next line, data is Decimal notation (signed) with field width 7
end
fclose(fid); % close the open file
clc,clear all
ax=zeros(1,6);
fid = fopen('dene3.txt'); % open file
for i=1:6
ax(i)=fscanf(fid,'%f',1) % read 1 value of data from the file in fixed point notation and store it on ax(i)
fclose(fid); % close the open file
ay=zeros(1,6);
fid = fopen('dene4.txt');
for i=1:6
ay(i)=fscanf(fid,'%d',1)
end
fclose(fid);
All the descriptions that I made and much more can be found on MATLAB documentation either online or on any installed MATLAB software, MATLAB got one of the best documentations you can find, please do try it.
##### 4 件のコメント表示非表示 3 件の古いコメント
Paulo Silva 2011 年 12 月 12 日
Regarding clc that would depend on what the user is doing, if he's using the command line or some kind of GUI (forms?!), clear all is something we usually do in MATLAB but with Visual Basic the variables must be initialized with their type so there's no need for it.
PS: My times of being a Visual Basic programmer are long gone and my memory of the way it worked isn't very good although I still have some books near by, I would gladly help on converting specific parts of the code but not all.

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

bek 2011 年 12 月 12 日
already I try to solve, but I couldn't and I'm trying still. I waiting for your good news, thank you.
##### 2 件のコメント表示非表示 1 件の古いコメント
bek 2011 年 12 月 12 日
This is not a fool, yes, this is homework, but believe that I have no idea with visual basic. If you do a part of that, I would try to do more. And teacher taught only Matlab but he want translate matlab code to vb code form from me, I think this fact is foolish :)

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

Daniel Shub 2011 年 12 月 12 日
• fopen is similar to FileOpen
• fclose is similar to FileClose
• fprintf is similar to FilePut
• fscanf is similar to File Get
A MATLAB "for" loop is like a Visual Basic "for" loop. With that you should be able to convert most of it.
##### 1 件のコメント表示非表示 なし
bek 2011 年 12 月 12 日
thank you Daniel, I will try use it.

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

### Community Treasure Hunt

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

Start Hunting!

Translated by