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)
  1 件のコメント
zein
zein 2020 年 8 月 14 日
Thanks for you reply.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by