Category: Matlab
Category Archives: Matlab
finding the mean/average of the smallest values in a row
hi ,
i have a row and i want to find the average of the smallest values and the position of this minimum.hi ,
i have a row and i want to find the average of the smallest values and the position of this minimum. hi ,
i have a row and i want to find the average of the smallest values and the position of this minimum. minimum MATLAB Answers — New Questions
Reduce noise and highlight peaks in DWS data
Introduction
Hi my name’s Mark and I’m an Italian CS undegraduate working on a internship regarding data analysis about Diffusing Wave Spectroscopy data coming from the ISS, from the FSL Soft Matter Dynamics facility. I decided to ask the help of you most experts in the field as I’ve never worked with MATLAB this extensively in all my career and I struggle to come up with simple solutions without implementing them myself (e.g. creating a function when it exists already). I do have the professors to ask help to if things get grim.
The topic
The raw data that we start with is composed of multiple grayscale colored .tif images. A single .tif is a single measurement. Please see the [myTif.png] attachment. After reading the image with tiffreadVolume and after some local normalization and Gaussian filtering, I am left with a graph. See [norm_of_changes.png] attachment. This graph has lots of noise. I suppose the noise is testament of the method used to get the graph in the first place (computing the norm of changes between blocks).
The following code is the one used to compute the data to be plotted.
% blocks = 1;
% [s, ~] = size(V_norm_smooth);
% V_norm_smooth 10000×200 tif after imgaussfilt
for i = 1 : s – blocks
change = V_norm_smooth(i + blocks, 🙂 – V_norm_smooth(i, :);
avg_change(i) = norm(change);
end
window_size = 21;
med_res = medfilt2(avg_change, [1, window_size]);
The objective
My goal is to highlight peaks present in the final plot.
Peaks are not always guaranteed to be as evident as they appear in the attached example. There might be only one peak, two, three or more. Several parameters already help with the reduction of "false positives", as we’ve experimented with them a lot and figured that an universal solution does not exist.
I’m quite of the idea there is no simple answer to the "problem". What I’d like is some pointers and directions on what a good approach would be for our case. The actual objective would be to higlight that region in [myTif.png] that looks like a barrier of unordered pixels with lots of different intensities. We are of the idea that this method might not be the best one, but as a research topic, it is interesting and worthwhile.Introduction
Hi my name’s Mark and I’m an Italian CS undegraduate working on a internship regarding data analysis about Diffusing Wave Spectroscopy data coming from the ISS, from the FSL Soft Matter Dynamics facility. I decided to ask the help of you most experts in the field as I’ve never worked with MATLAB this extensively in all my career and I struggle to come up with simple solutions without implementing them myself (e.g. creating a function when it exists already). I do have the professors to ask help to if things get grim.
The topic
The raw data that we start with is composed of multiple grayscale colored .tif images. A single .tif is a single measurement. Please see the [myTif.png] attachment. After reading the image with tiffreadVolume and after some local normalization and Gaussian filtering, I am left with a graph. See [norm_of_changes.png] attachment. This graph has lots of noise. I suppose the noise is testament of the method used to get the graph in the first place (computing the norm of changes between blocks).
The following code is the one used to compute the data to be plotted.
% blocks = 1;
% [s, ~] = size(V_norm_smooth);
% V_norm_smooth 10000×200 tif after imgaussfilt
for i = 1 : s – blocks
change = V_norm_smooth(i + blocks, 🙂 – V_norm_smooth(i, :);
avg_change(i) = norm(change);
end
window_size = 21;
med_res = medfilt2(avg_change, [1, window_size]);
The objective
My goal is to highlight peaks present in the final plot.
Peaks are not always guaranteed to be as evident as they appear in the attached example. There might be only one peak, two, three or more. Several parameters already help with the reduction of "false positives", as we’ve experimented with them a lot and figured that an universal solution does not exist.
I’m quite of the idea there is no simple answer to the "problem". What I’d like is some pointers and directions on what a good approach would be for our case. The actual objective would be to higlight that region in [myTif.png] that looks like a barrier of unordered pixels with lots of different intensities. We are of the idea that this method might not be the best one, but as a research topic, it is interesting and worthwhile. Introduction
Hi my name’s Mark and I’m an Italian CS undegraduate working on a internship regarding data analysis about Diffusing Wave Spectroscopy data coming from the ISS, from the FSL Soft Matter Dynamics facility. I decided to ask the help of you most experts in the field as I’ve never worked with MATLAB this extensively in all my career and I struggle to come up with simple solutions without implementing them myself (e.g. creating a function when it exists already). I do have the professors to ask help to if things get grim.
The topic
The raw data that we start with is composed of multiple grayscale colored .tif images. A single .tif is a single measurement. Please see the [myTif.png] attachment. After reading the image with tiffreadVolume and after some local normalization and Gaussian filtering, I am left with a graph. See [norm_of_changes.png] attachment. This graph has lots of noise. I suppose the noise is testament of the method used to get the graph in the first place (computing the norm of changes between blocks).
The following code is the one used to compute the data to be plotted.
% blocks = 1;
% [s, ~] = size(V_norm_smooth);
% V_norm_smooth 10000×200 tif after imgaussfilt
for i = 1 : s – blocks
change = V_norm_smooth(i + blocks, 🙂 – V_norm_smooth(i, :);
avg_change(i) = norm(change);
end
window_size = 21;
med_res = medfilt2(avg_change, [1, window_size]);
The objective
My goal is to highlight peaks present in the final plot.
Peaks are not always guaranteed to be as evident as they appear in the attached example. There might be only one peak, two, three or more. Several parameters already help with the reduction of "false positives", as we’ve experimented with them a lot and figured that an universal solution does not exist.
I’m quite of the idea there is no simple answer to the "problem". What I’d like is some pointers and directions on what a good approach would be for our case. The actual objective would be to higlight that region in [myTif.png] that looks like a barrier of unordered pixels with lots of different intensities. We are of the idea that this method might not be the best one, but as a research topic, it is interesting and worthwhile. noise reduction, image processing, plot, matlab function MATLAB Answers — New Questions
App Designer Crashes on start up
Hello, I am using matlab 2017b in Win10. Whenever I run "appdesigner" in the command line, I see a window pop up and close immediately. I also cannot open any .mlapp file. Also, there are not any warnings or errors popping up. I am very confused. Any ideas?Hello, I am using matlab 2017b in Win10. Whenever I run "appdesigner" in the command line, I see a window pop up and close immediately. I also cannot open any .mlapp file. Also, there are not any warnings or errors popping up. I am very confused. Any ideas? Hello, I am using matlab 2017b in Win10. Whenever I run "appdesigner" in the command line, I see a window pop up and close immediately. I also cannot open any .mlapp file. Also, there are not any warnings or errors popping up. I am very confused. Any ideas? app designer MATLAB Answers — New Questions
Time- series inputs for ODE Function
Dear all,
I hope you are all doing well.
I am trying to introduce the external inputs (forces) data which is time series. I have refered to a number of Matlab discussions and used the interp1 method to calculate in the ode function.
However, I found the results of the interplotion are different with the original data which I used. Furthermore, I have no idea about how to include the external inputs in ode. It does not accept the time-series data when I use it directly. I have attached the file and my code is following:
In the script, I just try to find the problem so, only 1 input (force) which is F_wave is enabled.
Thank you for your kind help.
Best wishes,
Yu
clear; clc;
global all_F
global ex_F
all_F = [];
ex_F = [];
syms z_T
filename = ‘Inputs_Force.xlsx’;
data = readtable(filename);
use_data=table2cell(data(:,1:6));
use_data=cell2mat(use_data);
Waveforce = use_data(:,2);
Wavemoment =use_data(:,3);
Windforce = use_data(:,5);
Windmoment = use_data(:,6);
tspan = 0:0.025:200;
figure,
subplot(3,1,2), plot(tspan, Windforce), xlabel(‘time/s’),ylabel(‘WindForce/N’);
subplot(3,1,1), plot(tspan, Waveforce), xlabel(‘time/s’),ylabel(‘WaveForce/N’);
subplot(3,1,3), plot(tspan, Wavemoment), xlabel(‘time/s’),ylabel(‘WaveMoment/N.m’)
h_R = 144.582; % m the height from the MSL to tower top;
H_T = 129.582; % m tower height from the tower bottom;
h_T = 15; % m height from tower base to tower bottom;
h = 29.94;
h_1 = 164.94;
z = 14.94; % m the distance from rotational centre to mooring line
h_t = 92.61; % m the distance from the centre of gravity of tower to rotational centre
h_p = 14.94; % m the distance from the centre of gravity of platform to rotational centre
g = 9.81;
m = 20093000; % kg /total mass
m_T = 1.263e6; % 8.6e5; % kg / tower
m_N = 1.017e6; % kg / nacelle
m_p = 1.7838e7; % kg /platform mass
xi_TA = 0.01;
I_p = 1.2507*10^10;% kg m2 /mass moment of inertia of platform
m_as = 9.4*10^6; % kg / Added mass for platform surge
I_a = 1.13*10^10; % kg m2 / Added mass for platform pitch
m_asp = -1.01*10^8; % kg m / Coupling effects of added mass bewteen surge and pitch
c_s = 1e5; % N s2/m2 / damping in surge motion (x-axis translation)
c_sp = -2e5; % coupled damping value between surge and platform pitch
c_p = 6e8; % viscous damping in pitch motionS
k_p = 2.190e9; % rotational stiffness of platform
k_mooringS = 7.965e4;
k_mooringSP = 1.162e6;
k_mooringP = 2.65e8;
% definition of TMD parameters
m_TMD = 1.2e5; % kg
k_TMD = 6.064e3; % kg/m
c_TMD = 1.2678e4; % kg/(m s)
X0 = [0 0 0 0 0 0]; % initial pitch motion
% ==================== definition of the tower properties===============
mu = 0.0084*z_T^3-1.077*z_T^2-171.5*z_T+2.96e04; % mass per length
EI = 1.905e06*z_T^3-2.47e08*z_T^2-5.208e10*z_T+6.851e12; % tower bending stiffness
Phi_TA = 0.9414*(z_T/H_T)^2+0.3468*(z_T/H_T)^3-1.073*(z_T/H_T)^4+1.3139*(z_T/H_T)^5-0.5289*(z_T/H_T)^6; % tower fore-aft first mode shape
% mass component
fun1 = mu*Phi_TA^2; m_TA = double(int(fun1,z_T,0,H_T));
fun2 = mu*Phi_TA; m_1 = double(int(fun2,z_T,0,H_T));
fun3 = mu*(z_T)*Phi_TA; m_2 = double(int(fun3,z_T,0,H_T));
fun4 = mu*(z_T); m_3 = double(int(fun4,z_T,0,H_T));
fun5 = mu*(z_T)^2; m_4 = double(int(fun5,z_T,0,H_T));
% fun6 = mu; m_T = double(int(fun6,z_T,0,H_T));
% Stiffness of the tower
D2y = diff(Phi_TA,z_T,2); Dy = diff(Phi_TA,z_T,1);
fun6 = EI*D2y^2; f1 = int(fun6,0,H_T);
fun7 = mu; f2 = int(fun7,z_T,H_T);
fun8 = g*(m_N+f2)*Dy^2; f3 = int(fun8,0,H_T);
k_TA = double(f1-f3);
% ================= definition of matrices ======================
M = [m_N+m_TA m_N+m_1 m_N*h_R+m_2;
m_N+m_1 m_N+m_p+m_T (m_N*h_R-m_p*h_p+m_3+m_T*h_T);
m_N*h_R+m_2 (m_N*h_R-m_p*h_p+m_3) m_N*h_R^2+I_p+m_4];
C = [2*xi_TA*sqrt(m_TA*k_TA) 0 0;
0 0 0;
0 0 0];
K = [k_TA 0 -(m_N+m_T)*g;
0 0 0;
-(m_N+m_T)*g 0 -(m_N*h_R+m_3-m_p*h_p)*g];
M_add = [0 0 0;
0 m_as m_asp;
0 m_asp I_a];
C_add = [0 0 0; % problem_
0 c_s c_sp;
0 c_sp c_p];
K_add = [0 0 0;
0 0 0;
0 0 k_p];
K_mooring = [0 0 0;
0 k_mooringS k_mooringSP;
0 k_mooringSP k_mooringP];
M_1 = M+M_add;
K_1 = K+K_mooring+K_add;
% the forces and moments are extracted from Orcaflex
F_wave = Waveforce;
M_wave = Wavemoment;
F_aero = Windforce;
M_aero = Windmoment;
% [V,D,W] = eig(K_1,M_1);
%
% w = diag(D).^0.5;
%
% T = (2*pi./w);
options = odeset(‘RelTol’,1e-10,’AbsTol’,1e-10);
[t,X] = ode45(@(t,X) reducedmodel(z,h_R,tspan,t,X,M,M_add,C,C_add,K,K_add,K_mooring,F_wave,M_wave,F_aero,M_aero),tspan,X0,options);
PtfmPitch_deg = X(:,3)*180/pi;
figure,
subplot(3,1,1), plot(t,X(:,1)),grid, xlabel(‘time/ s’), ylabel(‘TTDspFA/ m’)
subplot(3,1,2), plot(t,X(:,2)),grid, xlabel(‘time/ s’), ylabel(‘surge/ m’)
subplot(3,1,3), plot(t,PtfmPitch_deg),grid, xlabel(‘time/ s’), ylabel(‘platform pitch/ deg’)
function dXdt = reducedmodel(z,h_R,tspan,t,X,M,M_add,C,C_add,K,K_add,K_mooring,F_wave,M_wave,F_aero,M_aero)
global all_F
global ex_F
x = X(1:3);
xdot = X(4:6);
coe = 9.225e5;
coe1 = 1.16e10;
F1 = -coe*xdot(2)*abs(xdot(2));
F2 = -coe1*xdot(3)*abs(xdot(3));
F3 = interp1(tspan, F_wave, t,’spline’);
F4 = interp1(tspan, M_wave, ‘spline’);
F5 = interp1(tspan, F_aero, ‘spline’);
F6 = interp1(tspan, F_aero*h_R, ‘spline’);
F_external = [0;F3;0];
F=[0;F1;F2];
all_F = [all_F,F]; % drag force
ex_F = [ex_F, F_external]; % wave and wind forces
xddot = (M+M_add)(F+F_external-(K+K_add+K_mooring)*x-(C+C_add)*xdot);
dXdt = [xdot; xddot];
end
% function [u,wn]=eigsort(K_1,M_1)
% Omega=sqrt(eig(K_1,M_1));
% [vtem,~]=eig(K_1,M_1);
% [wn,isort]=sort(Omega);
% il=length(wn);
% for i=1:il
% v(:,i)=vtem(:,isort(i));
% end
% disp("The natural frequencies are (rad/sec)")
% wn
% endDear all,
I hope you are all doing well.
I am trying to introduce the external inputs (forces) data which is time series. I have refered to a number of Matlab discussions and used the interp1 method to calculate in the ode function.
However, I found the results of the interplotion are different with the original data which I used. Furthermore, I have no idea about how to include the external inputs in ode. It does not accept the time-series data when I use it directly. I have attached the file and my code is following:
In the script, I just try to find the problem so, only 1 input (force) which is F_wave is enabled.
Thank you for your kind help.
Best wishes,
Yu
clear; clc;
global all_F
global ex_F
all_F = [];
ex_F = [];
syms z_T
filename = ‘Inputs_Force.xlsx’;
data = readtable(filename);
use_data=table2cell(data(:,1:6));
use_data=cell2mat(use_data);
Waveforce = use_data(:,2);
Wavemoment =use_data(:,3);
Windforce = use_data(:,5);
Windmoment = use_data(:,6);
tspan = 0:0.025:200;
figure,
subplot(3,1,2), plot(tspan, Windforce), xlabel(‘time/s’),ylabel(‘WindForce/N’);
subplot(3,1,1), plot(tspan, Waveforce), xlabel(‘time/s’),ylabel(‘WaveForce/N’);
subplot(3,1,3), plot(tspan, Wavemoment), xlabel(‘time/s’),ylabel(‘WaveMoment/N.m’)
h_R = 144.582; % m the height from the MSL to tower top;
H_T = 129.582; % m tower height from the tower bottom;
h_T = 15; % m height from tower base to tower bottom;
h = 29.94;
h_1 = 164.94;
z = 14.94; % m the distance from rotational centre to mooring line
h_t = 92.61; % m the distance from the centre of gravity of tower to rotational centre
h_p = 14.94; % m the distance from the centre of gravity of platform to rotational centre
g = 9.81;
m = 20093000; % kg /total mass
m_T = 1.263e6; % 8.6e5; % kg / tower
m_N = 1.017e6; % kg / nacelle
m_p = 1.7838e7; % kg /platform mass
xi_TA = 0.01;
I_p = 1.2507*10^10;% kg m2 /mass moment of inertia of platform
m_as = 9.4*10^6; % kg / Added mass for platform surge
I_a = 1.13*10^10; % kg m2 / Added mass for platform pitch
m_asp = -1.01*10^8; % kg m / Coupling effects of added mass bewteen surge and pitch
c_s = 1e5; % N s2/m2 / damping in surge motion (x-axis translation)
c_sp = -2e5; % coupled damping value between surge and platform pitch
c_p = 6e8; % viscous damping in pitch motionS
k_p = 2.190e9; % rotational stiffness of platform
k_mooringS = 7.965e4;
k_mooringSP = 1.162e6;
k_mooringP = 2.65e8;
% definition of TMD parameters
m_TMD = 1.2e5; % kg
k_TMD = 6.064e3; % kg/m
c_TMD = 1.2678e4; % kg/(m s)
X0 = [0 0 0 0 0 0]; % initial pitch motion
% ==================== definition of the tower properties===============
mu = 0.0084*z_T^3-1.077*z_T^2-171.5*z_T+2.96e04; % mass per length
EI = 1.905e06*z_T^3-2.47e08*z_T^2-5.208e10*z_T+6.851e12; % tower bending stiffness
Phi_TA = 0.9414*(z_T/H_T)^2+0.3468*(z_T/H_T)^3-1.073*(z_T/H_T)^4+1.3139*(z_T/H_T)^5-0.5289*(z_T/H_T)^6; % tower fore-aft first mode shape
% mass component
fun1 = mu*Phi_TA^2; m_TA = double(int(fun1,z_T,0,H_T));
fun2 = mu*Phi_TA; m_1 = double(int(fun2,z_T,0,H_T));
fun3 = mu*(z_T)*Phi_TA; m_2 = double(int(fun3,z_T,0,H_T));
fun4 = mu*(z_T); m_3 = double(int(fun4,z_T,0,H_T));
fun5 = mu*(z_T)^2; m_4 = double(int(fun5,z_T,0,H_T));
% fun6 = mu; m_T = double(int(fun6,z_T,0,H_T));
% Stiffness of the tower
D2y = diff(Phi_TA,z_T,2); Dy = diff(Phi_TA,z_T,1);
fun6 = EI*D2y^2; f1 = int(fun6,0,H_T);
fun7 = mu; f2 = int(fun7,z_T,H_T);
fun8 = g*(m_N+f2)*Dy^2; f3 = int(fun8,0,H_T);
k_TA = double(f1-f3);
% ================= definition of matrices ======================
M = [m_N+m_TA m_N+m_1 m_N*h_R+m_2;
m_N+m_1 m_N+m_p+m_T (m_N*h_R-m_p*h_p+m_3+m_T*h_T);
m_N*h_R+m_2 (m_N*h_R-m_p*h_p+m_3) m_N*h_R^2+I_p+m_4];
C = [2*xi_TA*sqrt(m_TA*k_TA) 0 0;
0 0 0;
0 0 0];
K = [k_TA 0 -(m_N+m_T)*g;
0 0 0;
-(m_N+m_T)*g 0 -(m_N*h_R+m_3-m_p*h_p)*g];
M_add = [0 0 0;
0 m_as m_asp;
0 m_asp I_a];
C_add = [0 0 0; % problem_
0 c_s c_sp;
0 c_sp c_p];
K_add = [0 0 0;
0 0 0;
0 0 k_p];
K_mooring = [0 0 0;
0 k_mooringS k_mooringSP;
0 k_mooringSP k_mooringP];
M_1 = M+M_add;
K_1 = K+K_mooring+K_add;
% the forces and moments are extracted from Orcaflex
F_wave = Waveforce;
M_wave = Wavemoment;
F_aero = Windforce;
M_aero = Windmoment;
% [V,D,W] = eig(K_1,M_1);
%
% w = diag(D).^0.5;
%
% T = (2*pi./w);
options = odeset(‘RelTol’,1e-10,’AbsTol’,1e-10);
[t,X] = ode45(@(t,X) reducedmodel(z,h_R,tspan,t,X,M,M_add,C,C_add,K,K_add,K_mooring,F_wave,M_wave,F_aero,M_aero),tspan,X0,options);
PtfmPitch_deg = X(:,3)*180/pi;
figure,
subplot(3,1,1), plot(t,X(:,1)),grid, xlabel(‘time/ s’), ylabel(‘TTDspFA/ m’)
subplot(3,1,2), plot(t,X(:,2)),grid, xlabel(‘time/ s’), ylabel(‘surge/ m’)
subplot(3,1,3), plot(t,PtfmPitch_deg),grid, xlabel(‘time/ s’), ylabel(‘platform pitch/ deg’)
function dXdt = reducedmodel(z,h_R,tspan,t,X,M,M_add,C,C_add,K,K_add,K_mooring,F_wave,M_wave,F_aero,M_aero)
global all_F
global ex_F
x = X(1:3);
xdot = X(4:6);
coe = 9.225e5;
coe1 = 1.16e10;
F1 = -coe*xdot(2)*abs(xdot(2));
F2 = -coe1*xdot(3)*abs(xdot(3));
F3 = interp1(tspan, F_wave, t,’spline’);
F4 = interp1(tspan, M_wave, ‘spline’);
F5 = interp1(tspan, F_aero, ‘spline’);
F6 = interp1(tspan, F_aero*h_R, ‘spline’);
F_external = [0;F3;0];
F=[0;F1;F2];
all_F = [all_F,F]; % drag force
ex_F = [ex_F, F_external]; % wave and wind forces
xddot = (M+M_add)(F+F_external-(K+K_add+K_mooring)*x-(C+C_add)*xdot);
dXdt = [xdot; xddot];
end
% function [u,wn]=eigsort(K_1,M_1)
% Omega=sqrt(eig(K_1,M_1));
% [vtem,~]=eig(K_1,M_1);
% [wn,isort]=sort(Omega);
% il=length(wn);
% for i=1:il
% v(:,i)=vtem(:,isort(i));
% end
% disp("The natural frequencies are (rad/sec)")
% wn
% end Dear all,
I hope you are all doing well.
I am trying to introduce the external inputs (forces) data which is time series. I have refered to a number of Matlab discussions and used the interp1 method to calculate in the ode function.
However, I found the results of the interplotion are different with the original data which I used. Furthermore, I have no idea about how to include the external inputs in ode. It does not accept the time-series data when I use it directly. I have attached the file and my code is following:
In the script, I just try to find the problem so, only 1 input (force) which is F_wave is enabled.
Thank you for your kind help.
Best wishes,
Yu
clear; clc;
global all_F
global ex_F
all_F = [];
ex_F = [];
syms z_T
filename = ‘Inputs_Force.xlsx’;
data = readtable(filename);
use_data=table2cell(data(:,1:6));
use_data=cell2mat(use_data);
Waveforce = use_data(:,2);
Wavemoment =use_data(:,3);
Windforce = use_data(:,5);
Windmoment = use_data(:,6);
tspan = 0:0.025:200;
figure,
subplot(3,1,2), plot(tspan, Windforce), xlabel(‘time/s’),ylabel(‘WindForce/N’);
subplot(3,1,1), plot(tspan, Waveforce), xlabel(‘time/s’),ylabel(‘WaveForce/N’);
subplot(3,1,3), plot(tspan, Wavemoment), xlabel(‘time/s’),ylabel(‘WaveMoment/N.m’)
h_R = 144.582; % m the height from the MSL to tower top;
H_T = 129.582; % m tower height from the tower bottom;
h_T = 15; % m height from tower base to tower bottom;
h = 29.94;
h_1 = 164.94;
z = 14.94; % m the distance from rotational centre to mooring line
h_t = 92.61; % m the distance from the centre of gravity of tower to rotational centre
h_p = 14.94; % m the distance from the centre of gravity of platform to rotational centre
g = 9.81;
m = 20093000; % kg /total mass
m_T = 1.263e6; % 8.6e5; % kg / tower
m_N = 1.017e6; % kg / nacelle
m_p = 1.7838e7; % kg /platform mass
xi_TA = 0.01;
I_p = 1.2507*10^10;% kg m2 /mass moment of inertia of platform
m_as = 9.4*10^6; % kg / Added mass for platform surge
I_a = 1.13*10^10; % kg m2 / Added mass for platform pitch
m_asp = -1.01*10^8; % kg m / Coupling effects of added mass bewteen surge and pitch
c_s = 1e5; % N s2/m2 / damping in surge motion (x-axis translation)
c_sp = -2e5; % coupled damping value between surge and platform pitch
c_p = 6e8; % viscous damping in pitch motionS
k_p = 2.190e9; % rotational stiffness of platform
k_mooringS = 7.965e4;
k_mooringSP = 1.162e6;
k_mooringP = 2.65e8;
% definition of TMD parameters
m_TMD = 1.2e5; % kg
k_TMD = 6.064e3; % kg/m
c_TMD = 1.2678e4; % kg/(m s)
X0 = [0 0 0 0 0 0]; % initial pitch motion
% ==================== definition of the tower properties===============
mu = 0.0084*z_T^3-1.077*z_T^2-171.5*z_T+2.96e04; % mass per length
EI = 1.905e06*z_T^3-2.47e08*z_T^2-5.208e10*z_T+6.851e12; % tower bending stiffness
Phi_TA = 0.9414*(z_T/H_T)^2+0.3468*(z_T/H_T)^3-1.073*(z_T/H_T)^4+1.3139*(z_T/H_T)^5-0.5289*(z_T/H_T)^6; % tower fore-aft first mode shape
% mass component
fun1 = mu*Phi_TA^2; m_TA = double(int(fun1,z_T,0,H_T));
fun2 = mu*Phi_TA; m_1 = double(int(fun2,z_T,0,H_T));
fun3 = mu*(z_T)*Phi_TA; m_2 = double(int(fun3,z_T,0,H_T));
fun4 = mu*(z_T); m_3 = double(int(fun4,z_T,0,H_T));
fun5 = mu*(z_T)^2; m_4 = double(int(fun5,z_T,0,H_T));
% fun6 = mu; m_T = double(int(fun6,z_T,0,H_T));
% Stiffness of the tower
D2y = diff(Phi_TA,z_T,2); Dy = diff(Phi_TA,z_T,1);
fun6 = EI*D2y^2; f1 = int(fun6,0,H_T);
fun7 = mu; f2 = int(fun7,z_T,H_T);
fun8 = g*(m_N+f2)*Dy^2; f3 = int(fun8,0,H_T);
k_TA = double(f1-f3);
% ================= definition of matrices ======================
M = [m_N+m_TA m_N+m_1 m_N*h_R+m_2;
m_N+m_1 m_N+m_p+m_T (m_N*h_R-m_p*h_p+m_3+m_T*h_T);
m_N*h_R+m_2 (m_N*h_R-m_p*h_p+m_3) m_N*h_R^2+I_p+m_4];
C = [2*xi_TA*sqrt(m_TA*k_TA) 0 0;
0 0 0;
0 0 0];
K = [k_TA 0 -(m_N+m_T)*g;
0 0 0;
-(m_N+m_T)*g 0 -(m_N*h_R+m_3-m_p*h_p)*g];
M_add = [0 0 0;
0 m_as m_asp;
0 m_asp I_a];
C_add = [0 0 0; % problem_
0 c_s c_sp;
0 c_sp c_p];
K_add = [0 0 0;
0 0 0;
0 0 k_p];
K_mooring = [0 0 0;
0 k_mooringS k_mooringSP;
0 k_mooringSP k_mooringP];
M_1 = M+M_add;
K_1 = K+K_mooring+K_add;
% the forces and moments are extracted from Orcaflex
F_wave = Waveforce;
M_wave = Wavemoment;
F_aero = Windforce;
M_aero = Windmoment;
% [V,D,W] = eig(K_1,M_1);
%
% w = diag(D).^0.5;
%
% T = (2*pi./w);
options = odeset(‘RelTol’,1e-10,’AbsTol’,1e-10);
[t,X] = ode45(@(t,X) reducedmodel(z,h_R,tspan,t,X,M,M_add,C,C_add,K,K_add,K_mooring,F_wave,M_wave,F_aero,M_aero),tspan,X0,options);
PtfmPitch_deg = X(:,3)*180/pi;
figure,
subplot(3,1,1), plot(t,X(:,1)),grid, xlabel(‘time/ s’), ylabel(‘TTDspFA/ m’)
subplot(3,1,2), plot(t,X(:,2)),grid, xlabel(‘time/ s’), ylabel(‘surge/ m’)
subplot(3,1,3), plot(t,PtfmPitch_deg),grid, xlabel(‘time/ s’), ylabel(‘platform pitch/ deg’)
function dXdt = reducedmodel(z,h_R,tspan,t,X,M,M_add,C,C_add,K,K_add,K_mooring,F_wave,M_wave,F_aero,M_aero)
global all_F
global ex_F
x = X(1:3);
xdot = X(4:6);
coe = 9.225e5;
coe1 = 1.16e10;
F1 = -coe*xdot(2)*abs(xdot(2));
F2 = -coe1*xdot(3)*abs(xdot(3));
F3 = interp1(tspan, F_wave, t,’spline’);
F4 = interp1(tspan, M_wave, ‘spline’);
F5 = interp1(tspan, F_aero, ‘spline’);
F6 = interp1(tspan, F_aero*h_R, ‘spline’);
F_external = [0;F3;0];
F=[0;F1;F2];
all_F = [all_F,F]; % drag force
ex_F = [ex_F, F_external]; % wave and wind forces
xddot = (M+M_add)(F+F_external-(K+K_add+K_mooring)*x-(C+C_add)*xdot);
dXdt = [xdot; xddot];
end
% function [u,wn]=eigsort(K_1,M_1)
% Omega=sqrt(eig(K_1,M_1));
% [vtem,~]=eig(K_1,M_1);
% [wn,isort]=sort(Omega);
% il=length(wn);
% for i=1:il
% v(:,i)=vtem(:,isort(i));
% end
% disp("The natural frequencies are (rad/sec)")
% wn
% end ode45, differential equations, time series MATLAB Answers — New Questions
Index exceeds the number of array elements. Index must not exceed 4.
Index exceeds the number of array elements. Index must not exceed 4. I get it in Simulink. I’m getting this error and I couldn’t find a solution. Can you help me.Index exceeds the number of array elements. Index must not exceed 4. I get it in Simulink. I’m getting this error and I couldn’t find a solution. Can you help me. Index exceeds the number of array elements. Index must not exceed 4. I get it in Simulink. I’m getting this error and I couldn’t find a solution. Can you help me. simulink, matlab MATLAB Answers — New Questions
How do I find the value closest to my desired value in a vector
L=10;
n=1.45;
c=2.9979e8;
dt=6e-12; %time increment
Omega=1.020663297455751e+11;
GAMMAb=3.590391604102621e+08;
T=10*2*L*n/c; %total time
fmax = 1e9; %maximun frequency
%fs=80*fmax;
TA=-T/2:dt:T/2; %time axis for the signal
fs=1/dt; %sampling frequency
%t = (-T/2/dt:1:T/2/dt)*dt;
Nt=round(T/dt);
FA = (-Nt/2:Nt/2-1)/Nt*fs %frequency axis
How do I find a value closest to ftreqlims in frequency axis.
freqlims=Omega/2/pi-GAMMAb/2/piL=10;
n=1.45;
c=2.9979e8;
dt=6e-12; %time increment
Omega=1.020663297455751e+11;
GAMMAb=3.590391604102621e+08;
T=10*2*L*n/c; %total time
fmax = 1e9; %maximun frequency
%fs=80*fmax;
TA=-T/2:dt:T/2; %time axis for the signal
fs=1/dt; %sampling frequency
%t = (-T/2/dt:1:T/2/dt)*dt;
Nt=round(T/dt);
FA = (-Nt/2:Nt/2-1)/Nt*fs %frequency axis
How do I find a value closest to ftreqlims in frequency axis.
freqlims=Omega/2/pi-GAMMAb/2/pi L=10;
n=1.45;
c=2.9979e8;
dt=6e-12; %time increment
Omega=1.020663297455751e+11;
GAMMAb=3.590391604102621e+08;
T=10*2*L*n/c; %total time
fmax = 1e9; %maximun frequency
%fs=80*fmax;
TA=-T/2:dt:T/2; %time axis for the signal
fs=1/dt; %sampling frequency
%t = (-T/2/dt:1:T/2/dt)*dt;
Nt=round(T/dt);
FA = (-Nt/2:Nt/2-1)/Nt*fs %frequency axis
How do I find a value closest to ftreqlims in frequency axis.
freqlims=Omega/2/pi-GAMMAb/2/pi plot, min, grid MATLAB Answers — New Questions
Unique RGB colors for segmentation
Hi , I have an image. This image was generated by a segmentation artifact. Each geometric region has a color.
I need to use this as the ground truth, so each geometric region should have one label. The way I can accomplish this is by considering each unique color as a distinct label. But some os the masks have some transparency.
When I load this image, there is a alpha variable, which I guess it has to do with transparency. I am not an image processing person but I don’t know how to use this variable. Do I need this varibale to get each unique color? ANd how should I construct a disctionary so that I can check what class a particular pixel is from ?Hi , I have an image. This image was generated by a segmentation artifact. Each geometric region has a color.
I need to use this as the ground truth, so each geometric region should have one label. The way I can accomplish this is by considering each unique color as a distinct label. But some os the masks have some transparency.
When I load this image, there is a alpha variable, which I guess it has to do with transparency. I am not an image processing person but I don’t know how to use this variable. Do I need this varibale to get each unique color? ANd how should I construct a disctionary so that I can check what class a particular pixel is from ? Hi , I have an image. This image was generated by a segmentation artifact. Each geometric region has a color.
I need to use this as the ground truth, so each geometric region should have one label. The way I can accomplish this is by considering each unique color as a distinct label. But some os the masks have some transparency.
When I load this image, there is a alpha variable, which I guess it has to do with transparency. I am not an image processing person but I don’t know how to use this variable. Do I need this varibale to get each unique color? ANd how should I construct a disctionary so that I can check what class a particular pixel is from ? image processing, segmentation, digital image processing, computer vision MATLAB Answers — New Questions
About lindbland- master equation codes
Hallo, I was wondering if there is an easy code in matlab regarding solving master equations
Thank you in advance.Hallo, I was wondering if there is an easy code in matlab regarding solving master equations
Thank you in advance. Hallo, I was wondering if there is an easy code in matlab regarding solving master equations
Thank you in advance. lindbland, quantum mechanics MATLAB Answers — New Questions
Can process noise matrix be extracted from Linear System Model?
Given I have a linear discrete system identified by using the System Identification Toolbox, of the following standard form:
y = Cx + Du + e
x = Ax + Bu + Ke
If I extract A, B, C, D, K matrices in addition to NoiseVariance (which represents the variance of the model versus the measurements it was identified from), and additionally I have the variance of input, can I calculate the Q (process noise covariance) matrix from that information?
I looked at several topics and forum posts, for example:
https://www.mathworks.com/help/control/ug/kalman-filtering.html
https://www.mathworks.com/help/ident/ug/estimating-states-of-time-varying-systems-using-kalman-filters.html
https://www.mathworks.com/matlabcentral/answers/1722215-kalman-filter-discrete-system-kalmf-r-and-q-do-not-seem-to-influence-the-performance-of-the-kalman
https://www.mathworks.com/matlabcentral/answers/339275-how-to-set-q-and-r-in-a-kalman-filter
https://www.mathworks.com/matlabcentral/answers/122661-finding-out-q-and-r-matrices-of-a-given-system
https://dsp.stackexchange.com/questions/21796/question-about-q-matrix-model-process-covariance-in-kalman-filter
The consensus seems to be, that if I used the Matlab System Identification Toolbox to identify the linear discrete system (let’s call it ss1), then Q is given by:
% N is the order of the system, i.e. 3rd order N = 3
N = length(ss1.x0);
% Q = NoiseVariance * Identity + InputVariance * Contribution of Input
Q = ss1.NoiseVariance * eye(N) + ss1.B * inputVariance * ss1.B’
Is this accurate? Here’s an example from a system I identified.
% Generated by Matlab System Identification
N = 3;
NoiseVariance = 0.0026;
B = 1.0e-04 * [ -0.0001 0.0141 -0.1492];
% Provided by me (SISO system, just one input)
inputVariance = 0.001;
% Calculate process noise covariance
Q = NoiseVariance * eye(N) + B * inputVariance * B’;
I get this:
Q =
0.0026 -0.0000 0.0000
-0.0000 0.0026 -0.0000
0.0000 -0.0000 0.0026
…basically an identity because the B matrix (contribution of input directly into output) is:
B =
1.0e-04 *
-0.0001
0.0141
-0.1492Given I have a linear discrete system identified by using the System Identification Toolbox, of the following standard form:
y = Cx + Du + e
x = Ax + Bu + Ke
If I extract A, B, C, D, K matrices in addition to NoiseVariance (which represents the variance of the model versus the measurements it was identified from), and additionally I have the variance of input, can I calculate the Q (process noise covariance) matrix from that information?
I looked at several topics and forum posts, for example:
https://www.mathworks.com/help/control/ug/kalman-filtering.html
https://www.mathworks.com/help/ident/ug/estimating-states-of-time-varying-systems-using-kalman-filters.html
https://www.mathworks.com/matlabcentral/answers/1722215-kalman-filter-discrete-system-kalmf-r-and-q-do-not-seem-to-influence-the-performance-of-the-kalman
https://www.mathworks.com/matlabcentral/answers/339275-how-to-set-q-and-r-in-a-kalman-filter
https://www.mathworks.com/matlabcentral/answers/122661-finding-out-q-and-r-matrices-of-a-given-system
https://dsp.stackexchange.com/questions/21796/question-about-q-matrix-model-process-covariance-in-kalman-filter
The consensus seems to be, that if I used the Matlab System Identification Toolbox to identify the linear discrete system (let’s call it ss1), then Q is given by:
% N is the order of the system, i.e. 3rd order N = 3
N = length(ss1.x0);
% Q = NoiseVariance * Identity + InputVariance * Contribution of Input
Q = ss1.NoiseVariance * eye(N) + ss1.B * inputVariance * ss1.B’
Is this accurate? Here’s an example from a system I identified.
% Generated by Matlab System Identification
N = 3;
NoiseVariance = 0.0026;
B = 1.0e-04 * [ -0.0001 0.0141 -0.1492];
% Provided by me (SISO system, just one input)
inputVariance = 0.001;
% Calculate process noise covariance
Q = NoiseVariance * eye(N) + B * inputVariance * B’;
I get this:
Q =
0.0026 -0.0000 0.0000
-0.0000 0.0026 -0.0000
0.0000 -0.0000 0.0026
…basically an identity because the B matrix (contribution of input directly into output) is:
B =
1.0e-04 *
-0.0001
0.0141
-0.1492 Given I have a linear discrete system identified by using the System Identification Toolbox, of the following standard form:
y = Cx + Du + e
x = Ax + Bu + Ke
If I extract A, B, C, D, K matrices in addition to NoiseVariance (which represents the variance of the model versus the measurements it was identified from), and additionally I have the variance of input, can I calculate the Q (process noise covariance) matrix from that information?
I looked at several topics and forum posts, for example:
https://www.mathworks.com/help/control/ug/kalman-filtering.html
https://www.mathworks.com/help/ident/ug/estimating-states-of-time-varying-systems-using-kalman-filters.html
https://www.mathworks.com/matlabcentral/answers/1722215-kalman-filter-discrete-system-kalmf-r-and-q-do-not-seem-to-influence-the-performance-of-the-kalman
https://www.mathworks.com/matlabcentral/answers/339275-how-to-set-q-and-r-in-a-kalman-filter
https://www.mathworks.com/matlabcentral/answers/122661-finding-out-q-and-r-matrices-of-a-given-system
https://dsp.stackexchange.com/questions/21796/question-about-q-matrix-model-process-covariance-in-kalman-filter
The consensus seems to be, that if I used the Matlab System Identification Toolbox to identify the linear discrete system (let’s call it ss1), then Q is given by:
% N is the order of the system, i.e. 3rd order N = 3
N = length(ss1.x0);
% Q = NoiseVariance * Identity + InputVariance * Contribution of Input
Q = ss1.NoiseVariance * eye(N) + ss1.B * inputVariance * ss1.B’
Is this accurate? Here’s an example from a system I identified.
% Generated by Matlab System Identification
N = 3;
NoiseVariance = 0.0026;
B = 1.0e-04 * [ -0.0001 0.0141 -0.1492];
% Provided by me (SISO system, just one input)
inputVariance = 0.001;
% Calculate process noise covariance
Q = NoiseVariance * eye(N) + B * inputVariance * B’;
I get this:
Q =
0.0026 -0.0000 0.0000
-0.0000 0.0026 -0.0000
0.0000 -0.0000 0.0026
…basically an identity because the B matrix (contribution of input directly into output) is:
B =
1.0e-04 *
-0.0001
0.0141
-0.1492 system, digital signal processing MATLAB Answers — New Questions
Parfor Loop Error Using imwrite
Hi there,
I am trying to use a parfor loop which includes code which generates a RGB image and then saves it using the "imwrite" function within the parfor loop. It runs for a certain period of time and then randomly gives me the following error:
"PNG library failed: Could not open file..
Error in imwrite (line 566)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in HEATMAP_SCRIPT (line 65)
parfor i = 2:N"
The error seems to occur at random, sometimes occuring at 20% completion of the parfor loop or sometimes 30% etc. Any suggestions as to why this may be happening and how I can get around this?
ThanksHi there,
I am trying to use a parfor loop which includes code which generates a RGB image and then saves it using the "imwrite" function within the parfor loop. It runs for a certain period of time and then randomly gives me the following error:
"PNG library failed: Could not open file..
Error in imwrite (line 566)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in HEATMAP_SCRIPT (line 65)
parfor i = 2:N"
The error seems to occur at random, sometimes occuring at 20% completion of the parfor loop or sometimes 30% etc. Any suggestions as to why this may be happening and how I can get around this?
Thanks Hi there,
I am trying to use a parfor loop which includes code which generates a RGB image and then saves it using the "imwrite" function within the parfor loop. It runs for a certain period of time and then randomly gives me the following error:
"PNG library failed: Could not open file..
Error in imwrite (line 566)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in HEATMAP_SCRIPT (line 65)
parfor i = 2:N"
The error seems to occur at random, sometimes occuring at 20% completion of the parfor loop or sometimes 30% etc. Any suggestions as to why this may be happening and how I can get around this?
Thanks parfor, imwrite, saving, saving images in parfor, writing images in parfor, parfor loop save, parfor loop imwrite, parallel for loop saving images, parallel for loop save images, parallel for loop imwrite, save image as png, parfor loop save png MATLAB Answers — New Questions
supersonic nozzle design code error
I’m currently using the following code to try and determine nozzle designs; https://www.mathworks.com/help/aerotbx/ug/solving-for-the-exit-flow-of-a-supersonic-nozzle.html. Whenever I run the provided code from MatLab I get the following error;
‘plotExpansionSchematic’ is used in Solving for the Exit Flow of a Supersonic Nozzle.
Error in project413fluidflow (line 4)
upperNozzle = plotExpansionSchematic(‘uppernozzle’);
I’ve tried looking through the .m file that is provided that uses the plotExpansionSchematic function but I honestly don’t know what I’m looking for to fix this error and get the code working and plots to show up, I haven’t chnaged anything about the code except the initial conditions whihc I am using the following conditions; exitMach=1.25, exitPres=421.512, and backPres=154.2166. Any help in resolving this error would be greatly appreciated. I will also note that when I run the code that defines plotExpansionSchematic I also get an error, in case that is part of the issue I’m having the error is:
>> plotExpansionSchematic
Not enough input arguments.
Error in plotExpansionSchematic (line 182)
switch lower(type)I’m currently using the following code to try and determine nozzle designs; https://www.mathworks.com/help/aerotbx/ug/solving-for-the-exit-flow-of-a-supersonic-nozzle.html. Whenever I run the provided code from MatLab I get the following error;
‘plotExpansionSchematic’ is used in Solving for the Exit Flow of a Supersonic Nozzle.
Error in project413fluidflow (line 4)
upperNozzle = plotExpansionSchematic(‘uppernozzle’);
I’ve tried looking through the .m file that is provided that uses the plotExpansionSchematic function but I honestly don’t know what I’m looking for to fix this error and get the code working and plots to show up, I haven’t chnaged anything about the code except the initial conditions whihc I am using the following conditions; exitMach=1.25, exitPres=421.512, and backPres=154.2166. Any help in resolving this error would be greatly appreciated. I will also note that when I run the code that defines plotExpansionSchematic I also get an error, in case that is part of the issue I’m having the error is:
>> plotExpansionSchematic
Not enough input arguments.
Error in plotExpansionSchematic (line 182)
switch lower(type) I’m currently using the following code to try and determine nozzle designs; https://www.mathworks.com/help/aerotbx/ug/solving-for-the-exit-flow-of-a-supersonic-nozzle.html. Whenever I run the provided code from MatLab I get the following error;
‘plotExpansionSchematic’ is used in Solving for the Exit Flow of a Supersonic Nozzle.
Error in project413fluidflow (line 4)
upperNozzle = plotExpansionSchematic(‘uppernozzle’);
I’ve tried looking through the .m file that is provided that uses the plotExpansionSchematic function but I honestly don’t know what I’m looking for to fix this error and get the code working and plots to show up, I haven’t chnaged anything about the code except the initial conditions whihc I am using the following conditions; exitMach=1.25, exitPres=421.512, and backPres=154.2166. Any help in resolving this error would be greatly appreciated. I will also note that when I run the code that defines plotExpansionSchematic I also get an error, in case that is part of the issue I’m having the error is:
>> plotExpansionSchematic
Not enough input arguments.
Error in plotExpansionSchematic (line 182)
switch lower(type) aerospace toolbox, error MATLAB Answers — New Questions
color segmentation on a user-selected image using k-means clustering to identify and display different color classes, and visualizes the results with pie charts.
Hello all,
I hope you are doing well.
I need your help in adjusting this code to capture only the porosity (black shapes) that exists in the original image, instead of the inaccurate percentage results shown in the produced image and the pie chart.
I greatly appreciate your consideration.
Here is the code
% Do color segmentation by kmeans classification.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
% Check that user has the Image Processing Toolbox installed and licensed.
hasLicenseForToolbox = license(‘test’, ‘image_toolbox’);
if ~hasLicenseForToolbox
message = sprintf(‘Sorry, but you do not seem to have the Image Processing Toolbox.nDo you want to try to continue anyway?’);
reply = questdlg(message, ‘Toolbox missing’, ‘Yes’, ‘No’, ‘Yes’);
if strcmpi(reply, ‘No’)
return;
end
end
% Check that user has the Statistics and Machine Learning Toolbox installed and licensed.
hasLicenseForToolbox = license(‘test’, ‘Statistics_toolbox’);
if ~hasLicenseForToolbox
message = sprintf(‘Sorry, but you do not seem to have the Statistics and Machine Learning Toolbox.nDo you want to try to continue anyway?’);
reply = questdlg(message, ‘Toolbox missing’, ‘Yes’, ‘No’, ‘Yes’);
if strcmpi(reply, ‘No’)
return;
end
end
% Load the specific image file
fullFileName = ‘D:\OneDrive – York University\Zeiss Microscope\Dogbone TPUDownwards\Downwards TPU Traditional Direction.jpg’;
% fullFileName = ‘D:\OneDrive – York University\Zeiss Microscope\image J\Downwards\two\Image Downwards.png’;
if ~exist(fullFileName, ‘file’)
errorMessage = sprintf(‘Error: %s does not exist.’, fullFileName);
uiwait(warndlg(errorMessage));
return;
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorChannels should be = 3.
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels ~= 3
message = sprintf(‘You need to select an RGB image.’);
uiwait(errordlg(message));
return;
end
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title(‘Original Color Image’, ‘FontSize’, fontSize);
set(gcf, ‘Units’, ‘Normalized’, ‘Outerposition’, [0, 0, 1, 1]);
% Extract and display the color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
subplot(2, 2, 2);
imshow(redChannel);
title(‘Red Channel’, ‘FontSize’, fontSize);
subplot(2, 2, 3);
imshow(greenChannel);
title(‘Green Channel’, ‘FontSize’, fontSize);
subplot(2, 2, 4);
imshow(blueChannel);
title(‘Blue Channel’, ‘FontSize’, fontSize);
% Ask user how many color classes they want.
defaultValue = 5;
titleBar = ‘Enter an integer value’;
userPrompt = ‘Enter the number of color classes to find (2 through 6)’;
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput), return; end % Bail out if they clicked Cancel.
numberOfClasses = round(str2double(caUserInput{1}));
% Prepare data for k-means
imageData = double(reshape(rgbImage, [], 3));
indexes = kmeans(imageData, numberOfClasses);
% Reshape the cluster indexes to the original image dimensions
clusteredImage = reshape(indexes, size(rgbImage, 1), size(rgbImage, 2));
% Display clustered image
figure;
imshow(label2rgb(clusteredImage));
title(‘Clustered Image’, ‘FontSize’, fontSize);
% Calculate pixel counts for each class for the pie chart
classCounts = histcounts(indexes, 1:numberOfClasses+1);
% Create a custom color map based on the clustered image
uniqueClasses = unique(indexes);
colorsForPie = label2rgb(uniqueClasses); % Convert class numbers to RGB colors
colorsForPie = reshape(colorsForPie, [length(uniqueClasses), 3]); % Ensure it’s a Nx3 matrix for RGB
% Generate pie chart
figure;
pie(classCounts, arrayfun(@(x) sprintf(‘Class %d’, x), 1:numberOfClasses, ‘UniformOutput’, false));
colormap(colorsForPie); % Apply custom colors
% Title for pie chart
title(‘Pie Chart of Color Classes’, ‘FontSize’, fontSize);Hello all,
I hope you are doing well.
I need your help in adjusting this code to capture only the porosity (black shapes) that exists in the original image, instead of the inaccurate percentage results shown in the produced image and the pie chart.
I greatly appreciate your consideration.
Here is the code
% Do color segmentation by kmeans classification.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
% Check that user has the Image Processing Toolbox installed and licensed.
hasLicenseForToolbox = license(‘test’, ‘image_toolbox’);
if ~hasLicenseForToolbox
message = sprintf(‘Sorry, but you do not seem to have the Image Processing Toolbox.nDo you want to try to continue anyway?’);
reply = questdlg(message, ‘Toolbox missing’, ‘Yes’, ‘No’, ‘Yes’);
if strcmpi(reply, ‘No’)
return;
end
end
% Check that user has the Statistics and Machine Learning Toolbox installed and licensed.
hasLicenseForToolbox = license(‘test’, ‘Statistics_toolbox’);
if ~hasLicenseForToolbox
message = sprintf(‘Sorry, but you do not seem to have the Statistics and Machine Learning Toolbox.nDo you want to try to continue anyway?’);
reply = questdlg(message, ‘Toolbox missing’, ‘Yes’, ‘No’, ‘Yes’);
if strcmpi(reply, ‘No’)
return;
end
end
% Load the specific image file
fullFileName = ‘D:\OneDrive – York University\Zeiss Microscope\Dogbone TPUDownwards\Downwards TPU Traditional Direction.jpg’;
% fullFileName = ‘D:\OneDrive – York University\Zeiss Microscope\image J\Downwards\two\Image Downwards.png’;
if ~exist(fullFileName, ‘file’)
errorMessage = sprintf(‘Error: %s does not exist.’, fullFileName);
uiwait(warndlg(errorMessage));
return;
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorChannels should be = 3.
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels ~= 3
message = sprintf(‘You need to select an RGB image.’);
uiwait(errordlg(message));
return;
end
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title(‘Original Color Image’, ‘FontSize’, fontSize);
set(gcf, ‘Units’, ‘Normalized’, ‘Outerposition’, [0, 0, 1, 1]);
% Extract and display the color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
subplot(2, 2, 2);
imshow(redChannel);
title(‘Red Channel’, ‘FontSize’, fontSize);
subplot(2, 2, 3);
imshow(greenChannel);
title(‘Green Channel’, ‘FontSize’, fontSize);
subplot(2, 2, 4);
imshow(blueChannel);
title(‘Blue Channel’, ‘FontSize’, fontSize);
% Ask user how many color classes they want.
defaultValue = 5;
titleBar = ‘Enter an integer value’;
userPrompt = ‘Enter the number of color classes to find (2 through 6)’;
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput), return; end % Bail out if they clicked Cancel.
numberOfClasses = round(str2double(caUserInput{1}));
% Prepare data for k-means
imageData = double(reshape(rgbImage, [], 3));
indexes = kmeans(imageData, numberOfClasses);
% Reshape the cluster indexes to the original image dimensions
clusteredImage = reshape(indexes, size(rgbImage, 1), size(rgbImage, 2));
% Display clustered image
figure;
imshow(label2rgb(clusteredImage));
title(‘Clustered Image’, ‘FontSize’, fontSize);
% Calculate pixel counts for each class for the pie chart
classCounts = histcounts(indexes, 1:numberOfClasses+1);
% Create a custom color map based on the clustered image
uniqueClasses = unique(indexes);
colorsForPie = label2rgb(uniqueClasses); % Convert class numbers to RGB colors
colorsForPie = reshape(colorsForPie, [length(uniqueClasses), 3]); % Ensure it’s a Nx3 matrix for RGB
% Generate pie chart
figure;
pie(classCounts, arrayfun(@(x) sprintf(‘Class %d’, x), 1:numberOfClasses, ‘UniformOutput’, false));
colormap(colorsForPie); % Apply custom colors
% Title for pie chart
title(‘Pie Chart of Color Classes’, ‘FontSize’, fontSize); Hello all,
I hope you are doing well.
I need your help in adjusting this code to capture only the porosity (black shapes) that exists in the original image, instead of the inaccurate percentage results shown in the produced image and the pie chart.
I greatly appreciate your consideration.
Here is the code
% Do color segmentation by kmeans classification.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
% Check that user has the Image Processing Toolbox installed and licensed.
hasLicenseForToolbox = license(‘test’, ‘image_toolbox’);
if ~hasLicenseForToolbox
message = sprintf(‘Sorry, but you do not seem to have the Image Processing Toolbox.nDo you want to try to continue anyway?’);
reply = questdlg(message, ‘Toolbox missing’, ‘Yes’, ‘No’, ‘Yes’);
if strcmpi(reply, ‘No’)
return;
end
end
% Check that user has the Statistics and Machine Learning Toolbox installed and licensed.
hasLicenseForToolbox = license(‘test’, ‘Statistics_toolbox’);
if ~hasLicenseForToolbox
message = sprintf(‘Sorry, but you do not seem to have the Statistics and Machine Learning Toolbox.nDo you want to try to continue anyway?’);
reply = questdlg(message, ‘Toolbox missing’, ‘Yes’, ‘No’, ‘Yes’);
if strcmpi(reply, ‘No’)
return;
end
end
% Load the specific image file
fullFileName = ‘D:\OneDrive – York University\Zeiss Microscope\Dogbone TPUDownwards\Downwards TPU Traditional Direction.jpg’;
% fullFileName = ‘D:\OneDrive – York University\Zeiss Microscope\image J\Downwards\two\Image Downwards.png’;
if ~exist(fullFileName, ‘file’)
errorMessage = sprintf(‘Error: %s does not exist.’, fullFileName);
uiwait(warndlg(errorMessage));
return;
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorChannels should be = 3.
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels ~= 3
message = sprintf(‘You need to select an RGB image.’);
uiwait(errordlg(message));
return;
end
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title(‘Original Color Image’, ‘FontSize’, fontSize);
set(gcf, ‘Units’, ‘Normalized’, ‘Outerposition’, [0, 0, 1, 1]);
% Extract and display the color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
subplot(2, 2, 2);
imshow(redChannel);
title(‘Red Channel’, ‘FontSize’, fontSize);
subplot(2, 2, 3);
imshow(greenChannel);
title(‘Green Channel’, ‘FontSize’, fontSize);
subplot(2, 2, 4);
imshow(blueChannel);
title(‘Blue Channel’, ‘FontSize’, fontSize);
% Ask user how many color classes they want.
defaultValue = 5;
titleBar = ‘Enter an integer value’;
userPrompt = ‘Enter the number of color classes to find (2 through 6)’;
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput), return; end % Bail out if they clicked Cancel.
numberOfClasses = round(str2double(caUserInput{1}));
% Prepare data for k-means
imageData = double(reshape(rgbImage, [], 3));
indexes = kmeans(imageData, numberOfClasses);
% Reshape the cluster indexes to the original image dimensions
clusteredImage = reshape(indexes, size(rgbImage, 1), size(rgbImage, 2));
% Display clustered image
figure;
imshow(label2rgb(clusteredImage));
title(‘Clustered Image’, ‘FontSize’, fontSize);
% Calculate pixel counts for each class for the pie chart
classCounts = histcounts(indexes, 1:numberOfClasses+1);
% Create a custom color map based on the clustered image
uniqueClasses = unique(indexes);
colorsForPie = label2rgb(uniqueClasses); % Convert class numbers to RGB colors
colorsForPie = reshape(colorsForPie, [length(uniqueClasses), 3]); % Ensure it’s a Nx3 matrix for RGB
% Generate pie chart
figure;
pie(classCounts, arrayfun(@(x) sprintf(‘Class %d’, x), 1:numberOfClasses, ‘UniformOutput’, false));
colormap(colorsForPie); % Apply custom colors
% Title for pie chart
title(‘Pie Chart of Color Classes’, ‘FontSize’, fontSize); dbscan, kmeans, clustering MATLAB Answers — New Questions
Create a matrix and a map of Hydrologic Soil Group values using integer or character values
I want to create a matrix and a map of Hydrologic Soil Group (HSG) values using integer or character values. I have a vector of 8853×1 with the HSG letters (A, B, C or D) for different locations in St. Croix island (USVI). I want to produce a 102×263 matrix with those letters, using different scripts that I have available. The problem is that Matlab doesn’t let me produce a matrix with letters or character values (char format). The thing is, if I use numbers instead of letters (1, 2, 3 and 4), the matrix that is produced has all the numbers in double or float format, with decimal digits, and not whole numbers or integers.. But when I converted the vector to integer format, matlab doesn’t produce a matrix from that vector. I will use this matrix to plot a map of the island showing different colors according to the HSG values or letters. How can I produce a matrix and a map with integer and/or character values using a 8853×1 vector? Should I just round up the numbers in the matrix to the nearest whole number?I want to create a matrix and a map of Hydrologic Soil Group (HSG) values using integer or character values. I have a vector of 8853×1 with the HSG letters (A, B, C or D) for different locations in St. Croix island (USVI). I want to produce a 102×263 matrix with those letters, using different scripts that I have available. The problem is that Matlab doesn’t let me produce a matrix with letters or character values (char format). The thing is, if I use numbers instead of letters (1, 2, 3 and 4), the matrix that is produced has all the numbers in double or float format, with decimal digits, and not whole numbers or integers.. But when I converted the vector to integer format, matlab doesn’t produce a matrix from that vector. I will use this matrix to plot a map of the island showing different colors according to the HSG values or letters. How can I produce a matrix and a map with integer and/or character values using a 8853×1 vector? Should I just round up the numbers in the matrix to the nearest whole number? I want to create a matrix and a map of Hydrologic Soil Group (HSG) values using integer or character values. I have a vector of 8853×1 with the HSG letters (A, B, C or D) for different locations in St. Croix island (USVI). I want to produce a 102×263 matrix with those letters, using different scripts that I have available. The problem is that Matlab doesn’t let me produce a matrix with letters or character values (char format). The thing is, if I use numbers instead of letters (1, 2, 3 and 4), the matrix that is produced has all the numbers in double or float format, with decimal digits, and not whole numbers or integers.. But when I converted the vector to integer format, matlab doesn’t produce a matrix from that vector. I will use this matrix to plot a map of the island showing different colors according to the HSG values or letters. How can I produce a matrix and a map with integer and/or character values using a 8853×1 vector? Should I just round up the numbers in the matrix to the nearest whole number? matrix array, colormap, vectors MATLAB Answers — New Questions
Why is my variable being changed without assignment
Hello,
I have searched quite a lot on Google and cannot find anything related to what is happening, and just in general programming terms I cannot understand it either. I’m stumped and hope someone can shed some light. An analogy of what seems to be happening is this:
A = 1
B = A + 2 = 3 (and now A = 3!!!)
This makes no sense to me, how can the original value of A be getting changed without. This is my first time using Live Script and symbols, so perhaps there is something different around those concepts.
My code is below. The issue is that when I substitute 0 into yh(zero), it is also changing the value of yh. Thus when I perform a subs to calc yhNat (last line), the value it is referencing is no longer yh but actually yh(zero). If I leave out the calc of yh(zero) then yhNat calculates perfectly (15*exp((-2*t)) + 16*exp((-3*t))). The only thing I can think of is because the initial value assigned to both yh and yh(zero) is the same, perhaps Matlab is conflating/linking them somehow. Originally I just made yh(zero) a subs of yh, replacing all t’s with 0, but that didn’t work, hence the workaround.
Any help would be greatly appreciated, as I am fully stuck and all my years of messing around with programming languages aren’t helping at all to understand why this is happening.
% Homogenous solution
InitialVoltage = 1.5;
InitialCurrent = 2;
c_UD = 1/6;
%from earlier code roots.1 = -3, roots.2 = -2
syms yh yh(zero) yhNat dyh(t) dyh(zero) c_1 c_2
yh = c_1*exp(roots(1)*t) + c_2*exp(roots(2)*t)
dyh(t) = diff(yh)
dyh(zero) = subs(dyh(t),[t],[0]) == InitialCurrent/c_UD
%Evaluate yh(t) at t = 0:
yh(zero) = c_1*exp(roots(1)*t) + c_2*exp(roots(2)*t); %######### These two lines break it
yh(zero) = subs(yh(zero), [t], [0]) == vpa(InitialVoltage) %######### These two lines break it
%coefficients = solve([dyh(zero), yh(zero)], [c_1, c_2])
%Natural response
yhNat = subs(yh ,[c_1, c_2], [16, 15])Hello,
I have searched quite a lot on Google and cannot find anything related to what is happening, and just in general programming terms I cannot understand it either. I’m stumped and hope someone can shed some light. An analogy of what seems to be happening is this:
A = 1
B = A + 2 = 3 (and now A = 3!!!)
This makes no sense to me, how can the original value of A be getting changed without. This is my first time using Live Script and symbols, so perhaps there is something different around those concepts.
My code is below. The issue is that when I substitute 0 into yh(zero), it is also changing the value of yh. Thus when I perform a subs to calc yhNat (last line), the value it is referencing is no longer yh but actually yh(zero). If I leave out the calc of yh(zero) then yhNat calculates perfectly (15*exp((-2*t)) + 16*exp((-3*t))). The only thing I can think of is because the initial value assigned to both yh and yh(zero) is the same, perhaps Matlab is conflating/linking them somehow. Originally I just made yh(zero) a subs of yh, replacing all t’s with 0, but that didn’t work, hence the workaround.
Any help would be greatly appreciated, as I am fully stuck and all my years of messing around with programming languages aren’t helping at all to understand why this is happening.
% Homogenous solution
InitialVoltage = 1.5;
InitialCurrent = 2;
c_UD = 1/6;
%from earlier code roots.1 = -3, roots.2 = -2
syms yh yh(zero) yhNat dyh(t) dyh(zero) c_1 c_2
yh = c_1*exp(roots(1)*t) + c_2*exp(roots(2)*t)
dyh(t) = diff(yh)
dyh(zero) = subs(dyh(t),[t],[0]) == InitialCurrent/c_UD
%Evaluate yh(t) at t = 0:
yh(zero) = c_1*exp(roots(1)*t) + c_2*exp(roots(2)*t); %######### These two lines break it
yh(zero) = subs(yh(zero), [t], [0]) == vpa(InitialVoltage) %######### These two lines break it
%coefficients = solve([dyh(zero), yh(zero)], [c_1, c_2])
%Natural response
yhNat = subs(yh ,[c_1, c_2], [16, 15]) Hello,
I have searched quite a lot on Google and cannot find anything related to what is happening, and just in general programming terms I cannot understand it either. I’m stumped and hope someone can shed some light. An analogy of what seems to be happening is this:
A = 1
B = A + 2 = 3 (and now A = 3!!!)
This makes no sense to me, how can the original value of A be getting changed without. This is my first time using Live Script and symbols, so perhaps there is something different around those concepts.
My code is below. The issue is that when I substitute 0 into yh(zero), it is also changing the value of yh. Thus when I perform a subs to calc yhNat (last line), the value it is referencing is no longer yh but actually yh(zero). If I leave out the calc of yh(zero) then yhNat calculates perfectly (15*exp((-2*t)) + 16*exp((-3*t))). The only thing I can think of is because the initial value assigned to both yh and yh(zero) is the same, perhaps Matlab is conflating/linking them somehow. Originally I just made yh(zero) a subs of yh, replacing all t’s with 0, but that didn’t work, hence the workaround.
Any help would be greatly appreciated, as I am fully stuck and all my years of messing around with programming languages aren’t helping at all to understand why this is happening.
% Homogenous solution
InitialVoltage = 1.5;
InitialCurrent = 2;
c_UD = 1/6;
%from earlier code roots.1 = -3, roots.2 = -2
syms yh yh(zero) yhNat dyh(t) dyh(zero) c_1 c_2
yh = c_1*exp(roots(1)*t) + c_2*exp(roots(2)*t)
dyh(t) = diff(yh)
dyh(zero) = subs(dyh(t),[t],[0]) == InitialCurrent/c_UD
%Evaluate yh(t) at t = 0:
yh(zero) = c_1*exp(roots(1)*t) + c_2*exp(roots(2)*t); %######### These two lines break it
yh(zero) = subs(yh(zero), [t], [0]) == vpa(InitialVoltage) %######### These two lines break it
%coefficients = solve([dyh(zero), yh(zero)], [c_1, c_2])
%Natural response
yhNat = subs(yh ,[c_1, c_2], [16, 15]) live script, variable assignment MATLAB Answers — New Questions
I have difficulty using bird’s eye scope..
I am trying to add seonsors and simulate my roadrunner scenario using matlab.
I copied the commands in mathworks, but it doesn’t work. There’s an error at line 30 (about Bird’s eye scope)..
How can I sove this? please help me…I am trying to add seonsors and simulate my roadrunner scenario using matlab.
I copied the commands in mathworks, but it doesn’t work. There’s an error at line 30 (about Bird’s eye scope)..
How can I sove this? please help me… I am trying to add seonsors and simulate my roadrunner scenario using matlab.
I copied the commands in mathworks, but it doesn’t work. There’s an error at line 30 (about Bird’s eye scope)..
How can I sove this? please help me… roadrunner, bep, bird’s eye scope, matlab, error, seonsor, scenario, simulate MATLAB Answers — New Questions
Why is the scope of output of Liquid level system here showing a straight line and not an exponential like a step?
My components have been modelled as per image1.png
However, the output that I am getting when I click on scope and run looks like a straight line and not an exponential.
According to the book from which I am learning, it was supposed to be an exponential.
I have attached the slx file as well. Can someone explain why I am not getting an exponential as output?My components have been modelled as per image1.png
However, the output that I am getting when I click on scope and run looks like a straight line and not an exponential.
According to the book from which I am learning, it was supposed to be an exponential.
I have attached the slx file as well. Can someone explain why I am not getting an exponential as output? My components have been modelled as per image1.png
However, the output that I am getting when I click on scope and run looks like a straight line and not an exponential.
According to the book from which I am learning, it was supposed to be an exponential.
I have attached the slx file as well. Can someone explain why I am not getting an exponential as output? simulink, graph, model, control, transfer function MATLAB Answers — New Questions
(Strain vs Stress Curve) to (Stress Vs Strain Curve) Switch My X-axis into Y-axis in my plot
I plotted a strain- stress curve graph however, in physical materials studies stress(y-axis)-strain(x-axis) curve is the convention in plotting. I have tried to change the graph axis but to just recive a blank plot. I have tried everything but to no avail. What am I doing wrong?
clc
clear all
close all
E1=4000; %4GPa written in 4000 MPa
E2=5000; %5GPa written in 5000 MPa
Mu= 1.2*10^5; %this measures creep
stress0.norm = 800; %this is initial stress value is in MPa
for i=1:stress0.norm
strain.normal(i)=i/E1; % This is storing the values before yielding
end
for i=stress0.norm:1500 %this is the finising stress in MPa (after yielding
strain.normal(i)=(i/E1)+((i-stress0.norm)/E2); % This is storing the values after yielding
end
% The graph with what I started off
figure (‘Name’, ‘Linear Hardening Model’, ‘NumberTitle’, ‘off’)
plot (strain.normal,’b’);
hold on
plot (800,.2, ‘rx’, ‘LineWidth’, 2);
% plot (strain.normal,’b’);
title (‘Linear Hardening Model E2 +/- 10%’);
xticks(0:100:1500);
xlabel(‘stress(in MPa)’);
ylabel(‘strain’);
grid on
legend(‘Normal’,’Yielding Location’,’Location’,’NorthEast’)
% What I wanted to achieve but get a blank graph
figure (‘Name’, ‘Linear Hardening Models Issue ‘, ‘NumberTitle’, ‘off’)
plot (strain.normal,length(strain.normal),’b’);
hold on
plot (.2,800,’rx’, ‘LineWidth’, 2);
title (‘Linear Hardening Model’);
axis ([0 0.6 0 1500])
yticks(0:100:1500);
xticks
xlabel(‘strain’);
ylabel(‘stress(in MPa)’);
grid on
legend(‘Normal’,’Yielding Location’,’Location’,’NorthEast’)I plotted a strain- stress curve graph however, in physical materials studies stress(y-axis)-strain(x-axis) curve is the convention in plotting. I have tried to change the graph axis but to just recive a blank plot. I have tried everything but to no avail. What am I doing wrong?
clc
clear all
close all
E1=4000; %4GPa written in 4000 MPa
E2=5000; %5GPa written in 5000 MPa
Mu= 1.2*10^5; %this measures creep
stress0.norm = 800; %this is initial stress value is in MPa
for i=1:stress0.norm
strain.normal(i)=i/E1; % This is storing the values before yielding
end
for i=stress0.norm:1500 %this is the finising stress in MPa (after yielding
strain.normal(i)=(i/E1)+((i-stress0.norm)/E2); % This is storing the values after yielding
end
% The graph with what I started off
figure (‘Name’, ‘Linear Hardening Model’, ‘NumberTitle’, ‘off’)
plot (strain.normal,’b’);
hold on
plot (800,.2, ‘rx’, ‘LineWidth’, 2);
% plot (strain.normal,’b’);
title (‘Linear Hardening Model E2 +/- 10%’);
xticks(0:100:1500);
xlabel(‘stress(in MPa)’);
ylabel(‘strain’);
grid on
legend(‘Normal’,’Yielding Location’,’Location’,’NorthEast’)
% What I wanted to achieve but get a blank graph
figure (‘Name’, ‘Linear Hardening Models Issue ‘, ‘NumberTitle’, ‘off’)
plot (strain.normal,length(strain.normal),’b’);
hold on
plot (.2,800,’rx’, ‘LineWidth’, 2);
title (‘Linear Hardening Model’);
axis ([0 0.6 0 1500])
yticks(0:100:1500);
xticks
xlabel(‘strain’);
ylabel(‘stress(in MPa)’);
grid on
legend(‘Normal’,’Yielding Location’,’Location’,’NorthEast’) I plotted a strain- stress curve graph however, in physical materials studies stress(y-axis)-strain(x-axis) curve is the convention in plotting. I have tried to change the graph axis but to just recive a blank plot. I have tried everything but to no avail. What am I doing wrong?
clc
clear all
close all
E1=4000; %4GPa written in 4000 MPa
E2=5000; %5GPa written in 5000 MPa
Mu= 1.2*10^5; %this measures creep
stress0.norm = 800; %this is initial stress value is in MPa
for i=1:stress0.norm
strain.normal(i)=i/E1; % This is storing the values before yielding
end
for i=stress0.norm:1500 %this is the finising stress in MPa (after yielding
strain.normal(i)=(i/E1)+((i-stress0.norm)/E2); % This is storing the values after yielding
end
% The graph with what I started off
figure (‘Name’, ‘Linear Hardening Model’, ‘NumberTitle’, ‘off’)
plot (strain.normal,’b’);
hold on
plot (800,.2, ‘rx’, ‘LineWidth’, 2);
% plot (strain.normal,’b’);
title (‘Linear Hardening Model E2 +/- 10%’);
xticks(0:100:1500);
xlabel(‘stress(in MPa)’);
ylabel(‘strain’);
grid on
legend(‘Normal’,’Yielding Location’,’Location’,’NorthEast’)
% What I wanted to achieve but get a blank graph
figure (‘Name’, ‘Linear Hardening Models Issue ‘, ‘NumberTitle’, ‘off’)
plot (strain.normal,length(strain.normal),’b’);
hold on
plot (.2,800,’rx’, ‘LineWidth’, 2);
title (‘Linear Hardening Model’);
axis ([0 0.6 0 1500])
yticks(0:100:1500);
xticks
xlabel(‘strain’);
ylabel(‘stress(in MPa)’);
grid on
legend(‘Normal’,’Yielding Location’,’Location’,’NorthEast’) mechanics, materials science, plotting, axis MATLAB Answers — New Questions
Access FPGA External Memory Using AXI Manager over PCI Express Implement
I tried to follow the example:
Access FPGA External Memory Using AXI Manager over PCI Express – MATLAB & Simulink Example (mathworks.com)
I finished generating the bitstream file, programmed it to the board and then restarted.
When I used h = aximanager(‘Xilinx’,’ interface’,’pcie’); command, the following error occurs:
Error using pciexilinx_mex
Error: There is no compatibility FPGA-in-the-Loop device in the system. You may have not installed the driver required for this operation.
Error in hdlverifier.AXIManagerPCIe/openPCIeConnection
Error in hdlverifier.AXIManagerPCIe
Error in aximanager
Later I thought that I did not install the XDMA driver. After I installed it, the problem was still the same. I would like to ask how to solve this?
I implemented it with vivado 2022.2, matlab R2023b, KCU116 fpga board on windows.I tried to follow the example:
Access FPGA External Memory Using AXI Manager over PCI Express – MATLAB & Simulink Example (mathworks.com)
I finished generating the bitstream file, programmed it to the board and then restarted.
When I used h = aximanager(‘Xilinx’,’ interface’,’pcie’); command, the following error occurs:
Error using pciexilinx_mex
Error: There is no compatibility FPGA-in-the-Loop device in the system. You may have not installed the driver required for this operation.
Error in hdlverifier.AXIManagerPCIe/openPCIeConnection
Error in hdlverifier.AXIManagerPCIe
Error in aximanager
Later I thought that I did not install the XDMA driver. After I installed it, the problem was still the same. I would like to ask how to solve this?
I implemented it with vivado 2022.2, matlab R2023b, KCU116 fpga board on windows. I tried to follow the example:
Access FPGA External Memory Using AXI Manager over PCI Express – MATLAB & Simulink Example (mathworks.com)
I finished generating the bitstream file, programmed it to the board and then restarted.
When I used h = aximanager(‘Xilinx’,’ interface’,’pcie’); command, the following error occurs:
Error using pciexilinx_mex
Error: There is no compatibility FPGA-in-the-Loop device in the system. You may have not installed the driver required for this operation.
Error in hdlverifier.AXIManagerPCIe/openPCIeConnection
Error in hdlverifier.AXIManagerPCIe
Error in aximanager
Later I thought that I did not install the XDMA driver. After I installed it, the problem was still the same. I would like to ask how to solve this?
I implemented it with vivado 2022.2, matlab R2023b, KCU116 fpga board on windows. axi manager over pci express, fil, pciexilinx_mex MATLAB Answers — New Questions
How to assign a value to a variable in an equation
Hi
I have an equation and I want to assign a value to its variable
I wrote the code below but it didn’t change after running the code what can I do
Thanks
My code
clc
clear all
close all
warning off
zafar_queue =readtable(‘zafar_queue.xlsx’);
Y = zafar_queue.nVehContrib;
data = Y’;
x_train = floor(0.9*numel(data));
dataTrain =data(1:x_train);
n = length(dataTrain);
u = 0.1* randn(n,1) ;
% Import mydata
Opt = arxOptions;
Opt.InitialCondition = ‘estimate’;
arx30 = @(z)ar(dataTrain,[30], Opt)
z = Y(end)
frcast = arx30(z)
The result after compiling code is above without caculating z in itHi
I have an equation and I want to assign a value to its variable
I wrote the code below but it didn’t change after running the code what can I do
Thanks
My code
clc
clear all
close all
warning off
zafar_queue =readtable(‘zafar_queue.xlsx’);
Y = zafar_queue.nVehContrib;
data = Y’;
x_train = floor(0.9*numel(data));
dataTrain =data(1:x_train);
n = length(dataTrain);
u = 0.1* randn(n,1) ;
% Import mydata
Opt = arxOptions;
Opt.InitialCondition = ‘estimate’;
arx30 = @(z)ar(dataTrain,[30], Opt)
z = Y(end)
frcast = arx30(z)
The result after compiling code is above without caculating z in it Hi
I have an equation and I want to assign a value to its variable
I wrote the code below but it didn’t change after running the code what can I do
Thanks
My code
clc
clear all
close all
warning off
zafar_queue =readtable(‘zafar_queue.xlsx’);
Y = zafar_queue.nVehContrib;
data = Y’;
x_train = floor(0.9*numel(data));
dataTrain =data(1:x_train);
n = length(dataTrain);
u = 0.1* randn(n,1) ;
% Import mydata
Opt = arxOptions;
Opt.InitialCondition = ‘estimate’;
arx30 = @(z)ar(dataTrain,[30], Opt)
z = Y(end)
frcast = arx30(z)
The result after compiling code is above without caculating z in it variable, equation, assign MATLAB Answers — New Questions
Error when using if-else statement in MATLAB function block. How can I fix this error described below?
function m = fcn(Q, T_sat, T_w, sigma, rho_v, h_fg, M, P_v, R, g, beta, x, nu_novec, alpha_novec, k_m, d_pore, psi, k_f, rporous_outer, height_porous)
q_w = Q/(2*pi*rporous_outer*height_porous); %heat input converted to heat flux
if T_w>=T_sat
m = (((2*sigma)/(2-sigma))*((rho_v*(h_fg)^2)/T_sat)*((M/(2*pi*R*T_sat))^(0.5))*(1- ((P_v)/(2*rho_v*h_fg))));
else
m = (k_f*(0.5*(((g*beta*q_w*x^4)/(nu_novec*alpha_novec*k_m))*(((d_pore^2)*psi^3/(180*(1-psi^2)))/x^2))^(0.4)))/(x);
%the power of 0.4 is what triggers the complex number
end
When I run this code, I get the following error, which is triggered by the line ‘ m = (k_f*(0.5*(((g*beta*q_w*x^4)/(nu_novec*alpha_novec*k_m))*(((d_pore^2)*psi^3/(180*(1-psi^2)))/x^2))^(0.4)))/(x);
I’ve checked if any of the values result in a negative number, but none of the terms are negative, nor their result. I’ve run this separately, and this the same line works fine and I get a positive results without an complex number or any error? Why would this occur, does this error have to do anything with the if-else statement used? Any thoughts would be much appreciated.
I think this issue is triggered by the use of ^0.4, which cannot be changed. Why would an error/complex result occur in simulink and not in MATLAB?
Many thanksfunction m = fcn(Q, T_sat, T_w, sigma, rho_v, h_fg, M, P_v, R, g, beta, x, nu_novec, alpha_novec, k_m, d_pore, psi, k_f, rporous_outer, height_porous)
q_w = Q/(2*pi*rporous_outer*height_porous); %heat input converted to heat flux
if T_w>=T_sat
m = (((2*sigma)/(2-sigma))*((rho_v*(h_fg)^2)/T_sat)*((M/(2*pi*R*T_sat))^(0.5))*(1- ((P_v)/(2*rho_v*h_fg))));
else
m = (k_f*(0.5*(((g*beta*q_w*x^4)/(nu_novec*alpha_novec*k_m))*(((d_pore^2)*psi^3/(180*(1-psi^2)))/x^2))^(0.4)))/(x);
%the power of 0.4 is what triggers the complex number
end
When I run this code, I get the following error, which is triggered by the line ‘ m = (k_f*(0.5*(((g*beta*q_w*x^4)/(nu_novec*alpha_novec*k_m))*(((d_pore^2)*psi^3/(180*(1-psi^2)))/x^2))^(0.4)))/(x);
I’ve checked if any of the values result in a negative number, but none of the terms are negative, nor their result. I’ve run this separately, and this the same line works fine and I get a positive results without an complex number or any error? Why would this occur, does this error have to do anything with the if-else statement used? Any thoughts would be much appreciated.
I think this issue is triggered by the use of ^0.4, which cannot be changed. Why would an error/complex result occur in simulink and not in MATLAB?
Many thanks function m = fcn(Q, T_sat, T_w, sigma, rho_v, h_fg, M, P_v, R, g, beta, x, nu_novec, alpha_novec, k_m, d_pore, psi, k_f, rporous_outer, height_porous)
q_w = Q/(2*pi*rporous_outer*height_porous); %heat input converted to heat flux
if T_w>=T_sat
m = (((2*sigma)/(2-sigma))*((rho_v*(h_fg)^2)/T_sat)*((M/(2*pi*R*T_sat))^(0.5))*(1- ((P_v)/(2*rho_v*h_fg))));
else
m = (k_f*(0.5*(((g*beta*q_w*x^4)/(nu_novec*alpha_novec*k_m))*(((d_pore^2)*psi^3/(180*(1-psi^2)))/x^2))^(0.4)))/(x);
%the power of 0.4 is what triggers the complex number
end
When I run this code, I get the following error, which is triggered by the line ‘ m = (k_f*(0.5*(((g*beta*q_w*x^4)/(nu_novec*alpha_novec*k_m))*(((d_pore^2)*psi^3/(180*(1-psi^2)))/x^2))^(0.4)))/(x);
I’ve checked if any of the values result in a negative number, but none of the terms are negative, nor their result. I’ve run this separately, and this the same line works fine and I get a positive results without an complex number or any error? Why would this occur, does this error have to do anything with the if-else statement used? Any thoughts would be much appreciated.
I think this issue is triggered by the use of ^0.4, which cannot be changed. Why would an error/complex result occur in simulink and not in MATLAB?
Many thanks error, matlab function, if-else MATLAB Answers — New Questions