how to write Text file usiNG MATLAB
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Rik
le 11 Août 2020
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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur JSON Format dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!