필터 지우기
필터 지우기

how to write Text file usiNG MATLAB

조회 수: 2 (최근 30일)
zein
zein 2020년 8월 11일
댓글: zein 2020년 8월 14일
R-0
{
position (0.2 1.48 0.01);
pRef 2.0e-5;
fftFreq 1024;
}
I want to write a matlab script to produce a text file having a repated lines like the above line while changing the values inside
R-i
{
position (x(i) y(i) 0.01);
pRef 2.0e-5;
fftFreq 1024;
}
where, i, x(i) and y(i) are imported from x file
clc;
clear;
Excel= xlsread('receiverlocations.xlsx','points') ;
x= Excel(:,1)';%x
y= Excel(:,2)';%y
fid = fopen('ny.txt','wt');
for i=1:length(x)
i=i;
fprintf(fid, '{\n');
fprintf(fid, 'R-');
fprintf(fid,'i');
fprintf(fid, '\n');
fprintf(fid,'position','%6s %12s','x(i)','%6s %12s\n','y(i)');
fprintf(fid, '\n');
fprintf(fid, '}\n');
fprintf(fid, '\n');
end
fclose(fid)
I have tried the previous lines but variable like i is printed as i not the corresponding value
can anyone help?

채택된 답변

Rik
Rik 2020년 8월 11일
You forgot to put in the arguments as data:
clc;
clear;
Excel= xlsread('receiverlocations.xlsx','points') ;
x= Excel(:,1)';%x
y= Excel(:,2)';%y
fid = fopen('ny.txt','wt');
for i=1:length(x)
pRef=___
fftFreq=____
fprintf(fid, [...%split on multiple lines for readability, use 1 statement for speed
'R-%d\n',...
'{\n',...
' position %.2f %.2f\n',...
' pRef %e\n',...
' fftFreq %d\n',...
'}\n',...
'\n'],...
i,x(i),y(i),pRef,fftFreq);
end
fclose(fid)

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by