필터 지우기
필터 지우기

How can I open an empty external text file and fill it with the concatenation of two vectors and a char inbetween

조회 수: 1 (최근 30일)
I have two vectors
one is:
a=[1.4;3.1;6.5]
and the other one is:
b={VAR1,VAR2,VAR3}
How can I open an empty external text file, named a2.txt and fill the 3 first lines with
VAR1=1.4
VAR2=3.1
VAR3=6.5
I thank you in advance
Best regards,

답변 (1개)

Image Analyst
Image Analyst 2022년 4월 26일
편집: Image Analyst 2022년 4월 26일
Try this:
fid = fopen('a2.txt', 'wt');
fprintf(fid, '%s=%.1f\n', b{1}, a(1));
fprintf(fid, '%s=%.1f\n', b{2}, a(2));
fprintf(fid, '%s=%.1f\n', b{3}, a(3));
fclose(fid);

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by