how to write Text file usiNG MATLAB

2 次查看(过去 30 天)
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 个)

Community Treasure Hunt

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

Start Hunting!

Translated by