Can anyone please check this "for" loop for me?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Christoph F.
2017년 10월 16일
편집: Christoph F.
2017년 10월 16일
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.
채택된 답변
OCDER
2017년 10월 16일
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);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!