plotting in 3 for loop's
Afficher commentaires plus anciens
I am using 3 for loops.
frist for loop is used to change the speed in V_Wind
the second loop is used to change the angle theta
the third loop is used to change the speed of the vessel in t_vector
I am trying to have three plots of RWind. Note RWind depends in all the for loop parameters.
Therefore, I am trying to study the impact of theta (2nd loop) and Vwind (third loop) on the RWind
The figures of RWind should be as follows
figure(1) @ V_Wind(1)
plots the three thetas "thetas(1)& theta (2) & theta (3)" with respect to the speed profile
figure(2) @V_Wind(2)
............................................................
figure(3) @V_Wind (3)
............................................................
I am not being able to plot the figures, thus my code run non stop. Could you please let me know if there isa better way to do the plotting or if I made any mistake? Also, is it possible to show at which theta and V_Wind the figure is ploting?
Also, I attachted the .CSV files below.
clc
clear all
%Read speed vs time profile created
ST_prof = csvread("final_speed_profile.csv");
time_step = 1; %seconds
t_vector = ST_prof(:,1); %time in seconds
v= ST_prof(:,2);% m/s
plot(t_vector/60,v,'LineWidth',3)
xlabel('time,minutes')
ylabel('Ferry speed, m/s')
grid on
set(gca,'FontSize',14)
xlim([0 70.5])
%t_vector = 1:100;
%v =0.058:0.058:5.8;
%Cx interpolation
%Get the data from csv file
Cx_profile = csvread("Cxfirst.csv");
angle = Cx_profile(:,1); %RPM
Cx = Cx_profile(:,2); %N*m
%start kurve fitting
fCx = fit(angle,Cx,'linearinterp')
plot(fCx,angle,Cx)
xlabel('angle of attack')
ylabel('Cx')
set(gca,'FontSize',14)
%ylim([110 230])
rho_a = 1;
AT =20;
V_Wind=[6 5 4]; % avg speed of wind in NC Cape Hatteras in 2022 (m/s) [9]
%V_wind = 6.5; % [6.5 6.3 4.7 5.9 5.1 4.5 4.6 5.6 6.4 6.1 5.3 5.9 5.3 5.4 8.3 6.8 6.7 6.2];
theta=[45 90 180];
fCx_intial = fCx(0);
for j = 1:length(V_Wind)
j
%V_Wind = V_Wind(j)
for k = 1:length(theta)
fCx_data = fCx(theta(k))
for i = 1:length(t_vector)
CAA_Psi = -fCx_data; %fCx(theta);
CAA0=fCx_intial; %(0); %0.608982
RWind = 0.5*rho_a*CAA_Psi*AT*(V_Wind(j)^2)-0.5*rho_a*CAA0*AT*(v(i)^2); % Added resistance due to wind [N]([8] page 29, eq. 4.2)
RWind= abs(RWind);
hold on
figure(j)
plot(t_vector,RWind,'LineWidth',3)
title('freq vs. time ')
xlabel('time, seconds')
ylabel('fre, Hz')
set(gca,'FontSize',14)
end
hold off
end
end
Réponse acceptée
Plus de réponses (1)
Sulaymon Eshkabilov
le 2 Jan 2023
Two errors in spelling the data file names. And it is advised to use readmatrix() that is more efficient than csvread().
clc; clearvars
%Read speed vs time profile created
% ST_prof = csvread("speed_profile.csv"); % DATA file name must match with the orginal name
ST_prof = readmatrix("speed_profile.csv"); % DATA file name must match with the orginal name
time_step = 1; %seconds
t_vector = ST_prof(:,1); %time in seconds
v= ST_prof(:,2);% m/s
plot(t_vector/60,v,'LineWidth',3)
xlabel('time,minutes')
ylabel('Ferry speed, m/s')
grid on
set(gca,'FontSize',14)
xlim([0 70.5])
%t_vector = 1:100;
%v =0.058:0.058:5.8;
%Cx interpolation
%Get the data from csv file
% Cx_profile = csvread("CX.csv"); % DATA file name must match with the orginal name
Cx_profile = readmatrix("CX.csv"); % DATA file name must match with the orginal name
angle = Cx_profile(:,1); %RPM
Cx = Cx_profile(:,2); %N*m
%start kurve fitting
fCx = fit(angle,Cx,'linearinterp')
plot(fCx,angle,Cx)
xlabel('angle of attack')
ylabel('Cx')
set(gca,'FontSize',14)
%ylim([110 230])
rho_a = 1;
AT =20;
V_Wind=[6 5 4]; % avg speed of wind in NC Cape Hatteras in 2022 (m/s) [9]
%V_wind = 6.5; % [6.5 6.3 4.7 5.9 5.1 4.5 4.6 5.6 6.4 6.1 5.3 5.9 5.3 5.4 8.3 6.8 6.7 6.2];
theta=[45 90 180];
fCx_intial = fCx(0);
for j = 1:length(V_Wind)
j
%V_Wind = V_Wind(j)
for k = 1:length(theta)
fCx_data = fCx(theta(k))
for i = 1:length(t_vector)
CAA_Psi = -fCx_data; %fCx(theta);
CAA0=fCx_intial; %(0); %0.608982
RWind = 0.5*rho_a*CAA_Psi*AT*(V_Wind(j)^2)-0.5*rho_a*CAA0*AT*(v(i)^2); % Added resistance due to wind [N]([8] page 29, eq. 4.2)
RWind= abs(RWind);
hold on
figure(j)
plot(t_vector,RWind,'LineWidth',3)
title('freq vs. time ')
xlabel('time, seconds')
ylabel('fre, Hz')
set(gca,'FontSize',14)
end
hold off
end
end
Catégories
En savoir plus sur Animation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






