Borrar filtros
Borrar filtros

Can anyone please check this "for" loop for me?

2 visualizaciones (últimos 30 días)
Ismail Qeshta
Ismail Qeshta el 16 de Oct. de 2017
Comentada: OCDER el 17 de Oct. de 2017
Hi,
I would like to obtain the vector output of the following "for" loop:
close all; clear all;
C1=[1.25 1.36];
b=[10];
for i=1:2;
for j=1:2;
Formula=C1/(sqrt(b));
line1 = ['set C1 ' num2str(C1(i)) ';'];
fid=fopen('file.txt','w');
fprintf(fid,'%s\n',line1);
end
end
I would like to obtain the output from the Formula in the form of vector values [ ] printed in a file.
Thank you very much.
Regards, Ismail
  2 comentarios
Christoph F.
Christoph F. el 16 de Oct. de 2017
Editada: Christoph F. el 16 de Oct. de 2017
Your code repeatedly opens file.txt and never closes it.
I suggest opening file.txt once, outside the loop, and closing it after the loops are finished.
Ismail Qeshta
Ismail Qeshta el 16 de Oct. de 2017
Hi Christoph. Thanks for your suggestion. Can you please show me this in an example?

Iniciar sesión para comentar.

Respuesta aceptada

OCDER
OCDER el 16 de Oct. de 2017
clear
clc
close all
C1 = [1.25 1.36];
b = 10;
Formula = C1/(sqrt(b));
fid=fopen('file.txt', 'w');
fprintf(fid,'set C1 %f;\n', C1);
fclose(fid);
  2 comentarios
Ismail Qeshta
Ismail Qeshta el 17 de Oct. de 2017
Thank you very much Donald.
OCDER
OCDER el 17 de Oct. de 2017
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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!

Translated by