How to save a text file with number and text information?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Guilherme Weber Sampaio de Melo
le 1 Mar 2024
Commenté : Voss
le 2 Mar 2024
Hello, I have on my MATLAB code some variables containing values and filenames. Ex: lat1=1.2; lat2=3.2; long1=-44; long2=-34; grd=‘map.grd’; fault=‘fault.txt’; I would like to save one file in any output text format to be read by another code with a Shell code. Ex: file.txt containing all informations inside (1.2 3.2 -44 -34 map.grd fault.txt). I tried to use the writetable function as I have used before but it just work to values, it shows error when I tried to include the filenames (e.g map.grd). Does someone have any suggestion? Thanks in advance.
1 commentaire
Réponse acceptée
Voss
le 1 Mar 2024
Put the filenames in cell arrays.
Example:
lat1=1.2; lat2=3.2; long1=-44; long2=-34; grd='map.grd'; fault='fault.txt';
% first, I generate the error you might have gotten:
try
T = table(lat1,lat2,long1,long2,grd,fault) % doesn't work
catch e
disp(e.message);
end
% now, I put grd and fault in cell arrays:
T = table(lat1,lat2,long1,long2,{grd},{fault}) % works
% write the table to file:
writetable(T,'file.txt')
% check the contents of the txt file:
type file.txt
5 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Files 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!