Are you convert matlab code to visual basic code form for me, please?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
fprintf(fid,'%8.5f\n',1.87*x(i)); % Please write description
end
fclose(fid); % Please write description
fid = fopen('dene4.txt','w'); % Please write description
for i=1:6
fprintf(fid,'%7d\n',12*i); % Please write description
end
fclose(fid); % Please write description
clc,clear all
ax=zeros(1,6);
fid = fopen('dene3.txt'); % Please write description
for i=1:6
ax(i)=fscanf(fid,'%f',1) % Please write description
fclose(fid); % Please write description
ay=zeros(1,6);
fid = fopen('dene4.txt');
for i=1:6
ay(i)=fscanf(fid,'%d',1)
end
fclose(fid);
0 comentarios
Respuestas (3)
Paulo Silva
el 11 de Dic. de 2011
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 comentarios
Jan
el 12 de Dic. de 2011
@Paulo: I agree. Do you know how to convert "clc; clear all"?
@bek: It would be helpful if you post, what you have done so far and which problems occur.
Paulo Silva
el 12 de Dic. de 2011
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
el 12 de Dic. de 2011
2 comentarios
Paulo Silva
el 12 de Dic. de 2011
So keep waiting, someone might be foolish enough to do all that hard work for you, if the code is homework or something similar you are the one that should be working hard on it not us, we can help with specific MATLAB problems not Visual Basic or other language.
Daniel Shub
el 12 de Dic. de 2011
- 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.
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!