how to output data into a text file
27 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nicholas Deosaran
le 24 Sep 2020
Réponse apportée : Jalaj Gambhir
le 28 Sep 2020
Hello everyone,
I am having an issue with how to export data to a text file.
I have been looking at https://www.mathworks.com/help/matlab/import_export/writing-to-text-data-files-with-low-level-io.html for help but not getting anwere.
below is my code that I have and would like to export it to 3 different text files.
clc
clear
% Given basin parameters
g = 9.81; % gravity
h = 15; % water depth
l = 500; % basin length
n = 1; % node
% Function to get wave length
L1 = 2*l/n;
disp('At node = 1');
disp(['Wavelength L = ' num2str(L1)]);
% Function to get wave period
T1 = (2*l)/(n*sqrt(g*h));
disp(['Wave Period at T = ' num2str(T1)]);
% Given basin parameters
g = 9.81; % gravity
h = 15; % water depth
l = 500; % basin length
a = 2; % node
L2 = 2*l/a;
disp('At node = 2');
disp(['Wavelength L = ' num2str(L2)]);
% Function to get wave period
T2 = (2*l)/(a*sqrt(g*h));
disp(['Wave Period at T = ' num2str(T2)]);
% Given basin parameters
g = 9.81; % gravity
h = 15; % water depth
l = 500; % basin length
b = 3; % node
L3 = 2*l/b;
disp('At node = 3');
disp(['Wavelength L = ' num2str(L3)]);
% Function to get wave period
T3 = (2*l)/(b*sqrt(g*h));
disp(['Wave Period at T = ' num2str(T3)]);
%information needed for free surface profile
t=0;
H = 1; % wave height
x = 0:l;
k1 = 2*pi/L1;
k2 = 2*pi/L2;
k3 = 2*pi/L3;
sigma1 = 2*pi/T1;
sigma2 = 2*pi/T2;
sigma3 = 2*pi/T3;
N1 = H/2*cos(k1*x)*cos(sigma1*t);
N2 = H/2*cos(k1*x)*cos(sigma2*t);
N3 = H/2*cos(k1*x)*cos(sigma3*t);
subplot(3,1,1);
N1 = H/2*cos(k1*x)*cos(sigma1*t);
plot(x,N1, 'r')
hold on
yline(0);
ylim([-1 1])
title ('mode n = 1, L = l/2')
xlabel ('x(m)')
ylabel ('eta (m)')
legend('H/2*cos(k1*x)*cos(sigma2*t)')
subplot(3,1,2)
N2 = H/2*cos(k2*x)*cos(sigma2*t);
plot (x,N2,'r');
hold on
yline(0);
ylim([-1 1])
title ('mode n = 2, L = l')
xlabel ('x(m)')
ylabel ('eta (m)')
legend('H/2*cos(k2*x)*cos(sigma2*t)')
subplot(3,1,3)
N3 = H/2*cos(k3*x)*cos(sigma3*t);
plot(x, N3, 'r')
hold on
yline(0);
ylim([-1 1])
title ('mode n = 3, L= 2l/3')
xlabel ('x(m)')
ylabel ('eta (m)')
legend('H/2*cos(k3*x)*cos(sigma2*t)')
Thank you for your help
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing 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!