Category: Matlab
Category Archives: Matlab
X-Axis Boxplot Shift
Is there a way in matlab to use boxplot or boxchart to shift the boxplot to the side of additional data lines such as a scatter or line plot? I am looking to put my scatter point on x-axis 1 and 2 with the boxplot to the side at x-axis 0.5 and 2.5. Image attached of my data and then of an image I found of someone doing this in R.Is there a way in matlab to use boxplot or boxchart to shift the boxplot to the side of additional data lines such as a scatter or line plot? I am looking to put my scatter point on x-axis 1 and 2 with the boxplot to the side at x-axis 0.5 and 2.5. Image attached of my data and then of an image I found of someone doing this in R. Is there a way in matlab to use boxplot or boxchart to shift the boxplot to the side of additional data lines such as a scatter or line plot? I am looking to put my scatter point on x-axis 1 and 2 with the boxplot to the side at x-axis 0.5 and 2.5. Image attached of my data and then of an image I found of someone doing this in R. boxplot, boxchart, scatter plot, lineplot, multiplot MATLAB Answers — New Questions
plz help me, worm gear was not generated
The worm gear turns in the direction of the base axis rotationThe worm gear turns in the direction of the base axis rotation The worm gear turns in the direction of the base axis rotation #gear #worm gear #matlab MATLAB Answers — New Questions
MATLab does not solve for my variable and only solves the root of the equation
Hello, I’m new to MATlab, here is the code and the equation:
syms a H Q x y z b c d e f g h
eqn = x + y*a + z*H + b*a^2 + c*H^2 + d*a^3 + e*H^3 + f*a*H + g*a^2*H + h*a*H^2 == Q;
solutions = solve(eqn, a)
variables x y z b c d e f g and h are all constants but they are long numbers so I decided to write them like this. I would like MATlab to solve for a but it just gives me the root of the equation which is useless to me. I even tried replacing the other variables like Q and H with constant to no avail. Even with the only variable being a MATlab still solves for roots instead for a…Hello, I’m new to MATlab, here is the code and the equation:
syms a H Q x y z b c d e f g h
eqn = x + y*a + z*H + b*a^2 + c*H^2 + d*a^3 + e*H^3 + f*a*H + g*a^2*H + h*a*H^2 == Q;
solutions = solve(eqn, a)
variables x y z b c d e f g and h are all constants but they are long numbers so I decided to write them like this. I would like MATlab to solve for a but it just gives me the root of the equation which is useless to me. I even tried replacing the other variables like Q and H with constant to no avail. Even with the only variable being a MATlab still solves for roots instead for a… Hello, I’m new to MATlab, here is the code and the equation:
syms a H Q x y z b c d e f g h
eqn = x + y*a + z*H + b*a^2 + c*H^2 + d*a^3 + e*H^3 + f*a*H + g*a^2*H + h*a*H^2 == Q;
solutions = solve(eqn, a)
variables x y z b c d e f g and h are all constants but they are long numbers so I decided to write them like this. I would like MATlab to solve for a but it just gives me the root of the equation which is useless to me. I even tried replacing the other variables like Q and H with constant to no avail. Even with the only variable being a MATlab still solves for roots instead for a… solving for root instead for variable MATLAB Answers — New Questions
How can I convert my matlab code into python?
close all;
clear all;
clc;
Datafiles = fileDatastore("temp_summary.12*.txt","ReadFcn",@readMonth,"UniformRead",true);
dataAll = readall(Datafiles);
dataAll.Year = year(dataAll.Day);
dataAll.Month = month(dataAll.Day);
dataAll.DD = day(dataAll.Day);
LY = (dataAll.Month(:)==2 & dataAll.DD(:)==29);
dataAll(LY,:) = [];
% Unstack variables
minT_tbl = unstack(dataAll,"MinT","Year","GroupingVariables", ["Month","DD"],"VariableNamingRule","preserve")
maxT_tbl = unstack(dataAll,"MaxT","Year","GroupingVariables", ["Month","DD"],"VariableNamingRule","preserve")
yrs =str2double(minT_tbl.Properties.VariableNames(3:end))’;
% find min
[Tmin,idxMn] = min(minT_tbl{:,3:end},[],2,’omitnan’);
Tmin_yr = yrs(idxMn);
% find max
[Tmax,idxMx] = max(maxT_tbl{:,3:end},[],2,’omitnan’);
Tmax_yr = yrs(idxMx);
% find low high
[lowTMax,idxMx] = min(maxT_tbl{:,3:end},[],2,’omitnan’);
LowTMax_yr = yrs(idxMx);
% find high low
[highlowTMn,idxMn] = max(minT_tbl{:,3:end},[],2,’omitnan’);
HighLowT_yr = yrs(idxMn);
% find avg high
AvgTMx = round(mean(table2array(maxT_tbl(:,3:end)),2,’omitnan’));
% find avg low
AvgTMn = round(mean(table2array(minT_tbl(:,3:end)),2,’omitnan’));
% Results
tempTbl = [maxT_tbl(:,["Month","DD"]), table(Tmax,Tmax_yr,AvgTMx,lowTMax,LowTMax_yr,Tmin,Tmin_yr,AvgTMn,highlowTMn,HighLowT_yr)]
tempTbl2 = splitvars(tempTbl)
FID = fopen(‘Meda 12 Temperature Climatology.txt’,’w’);
report_date = datetime(‘now’,’format’,’yyyy-MM-dd HH:MM’);
fprintf(FID,’Meda 12 Temperature Climatology at %s n’, report_date);
fprintf(FID,"Month DD Temp Max (°F) Tmax_yr AvgTMax (°F) lowTMax (°F) LowTMax_yr TempMin (°F) TMin_yr AvgTMin (°F) HighlowTMin (°F) HighlowT_yr n");
fprintf(FID,’%3d %6d %7d %14d %11d %11d %15d %11d %13d %10d %13d %17d n’, tempTbl2{:,1:end}’);
fclose(FID);
winopen(‘Meda 12 Temperature Climatology.txt’)
function Tbl = readMonth(filename)
opts = detectImportOptions(filename);
opts.ConsecutiveDelimitersRule = ‘join’;
opts.MissingRule = ‘omitvar’;
opts = setvartype(opts,’double’);
opts.VariableNames = ["Day","MaxT","MinT","AvgT"];
Tbl = readtable(filename,opts);
Tbl = standardizeMissing(Tbl,{999,’N/A’},"DataVariables",{‘MaxT’,’MinT’,’AvgT’});
Tbl = standardizeMissing(Tbl,{-99,’N/A’},"DataVariables",{‘MaxT’,’MinT’,’AvgT’});
[~,basename] = fileparts(filename);
% use the base file name, not the full file name:
d = str2double(extract(basename,digitsPattern));
if ~leapyear(d(3)) && d(2) == 2 % February of a non-leap-year
Tbl(Tbl.Day == 29,:) = []; % remove the 29th day data, if any
end
Tbl.Day = datetime(d(3),d(2),Tbl.Day);
end
function tf = leapyear(y)
if mod(y,4) % year is not divisible by 4
tf = false; % it is a common year
elseif mod(y,100) % year is not divisible by 100
tf = true; % it is a leap year
elseif mod(y,400) % year is not divisible by 400
tf = false; % it is a common year
else
tf = true; % it is a leap year
end
endclose all;
clear all;
clc;
Datafiles = fileDatastore("temp_summary.12*.txt","ReadFcn",@readMonth,"UniformRead",true);
dataAll = readall(Datafiles);
dataAll.Year = year(dataAll.Day);
dataAll.Month = month(dataAll.Day);
dataAll.DD = day(dataAll.Day);
LY = (dataAll.Month(:)==2 & dataAll.DD(:)==29);
dataAll(LY,:) = [];
% Unstack variables
minT_tbl = unstack(dataAll,"MinT","Year","GroupingVariables", ["Month","DD"],"VariableNamingRule","preserve")
maxT_tbl = unstack(dataAll,"MaxT","Year","GroupingVariables", ["Month","DD"],"VariableNamingRule","preserve")
yrs =str2double(minT_tbl.Properties.VariableNames(3:end))’;
% find min
[Tmin,idxMn] = min(minT_tbl{:,3:end},[],2,’omitnan’);
Tmin_yr = yrs(idxMn);
% find max
[Tmax,idxMx] = max(maxT_tbl{:,3:end},[],2,’omitnan’);
Tmax_yr = yrs(idxMx);
% find low high
[lowTMax,idxMx] = min(maxT_tbl{:,3:end},[],2,’omitnan’);
LowTMax_yr = yrs(idxMx);
% find high low
[highlowTMn,idxMn] = max(minT_tbl{:,3:end},[],2,’omitnan’);
HighLowT_yr = yrs(idxMn);
% find avg high
AvgTMx = round(mean(table2array(maxT_tbl(:,3:end)),2,’omitnan’));
% find avg low
AvgTMn = round(mean(table2array(minT_tbl(:,3:end)),2,’omitnan’));
% Results
tempTbl = [maxT_tbl(:,["Month","DD"]), table(Tmax,Tmax_yr,AvgTMx,lowTMax,LowTMax_yr,Tmin,Tmin_yr,AvgTMn,highlowTMn,HighLowT_yr)]
tempTbl2 = splitvars(tempTbl)
FID = fopen(‘Meda 12 Temperature Climatology.txt’,’w’);
report_date = datetime(‘now’,’format’,’yyyy-MM-dd HH:MM’);
fprintf(FID,’Meda 12 Temperature Climatology at %s n’, report_date);
fprintf(FID,"Month DD Temp Max (°F) Tmax_yr AvgTMax (°F) lowTMax (°F) LowTMax_yr TempMin (°F) TMin_yr AvgTMin (°F) HighlowTMin (°F) HighlowT_yr n");
fprintf(FID,’%3d %6d %7d %14d %11d %11d %15d %11d %13d %10d %13d %17d n’, tempTbl2{:,1:end}’);
fclose(FID);
winopen(‘Meda 12 Temperature Climatology.txt’)
function Tbl = readMonth(filename)
opts = detectImportOptions(filename);
opts.ConsecutiveDelimitersRule = ‘join’;
opts.MissingRule = ‘omitvar’;
opts = setvartype(opts,’double’);
opts.VariableNames = ["Day","MaxT","MinT","AvgT"];
Tbl = readtable(filename,opts);
Tbl = standardizeMissing(Tbl,{999,’N/A’},"DataVariables",{‘MaxT’,’MinT’,’AvgT’});
Tbl = standardizeMissing(Tbl,{-99,’N/A’},"DataVariables",{‘MaxT’,’MinT’,’AvgT’});
[~,basename] = fileparts(filename);
% use the base file name, not the full file name:
d = str2double(extract(basename,digitsPattern));
if ~leapyear(d(3)) && d(2) == 2 % February of a non-leap-year
Tbl(Tbl.Day == 29,:) = []; % remove the 29th day data, if any
end
Tbl.Day = datetime(d(3),d(2),Tbl.Day);
end
function tf = leapyear(y)
if mod(y,4) % year is not divisible by 4
tf = false; % it is a common year
elseif mod(y,100) % year is not divisible by 100
tf = true; % it is a leap year
elseif mod(y,400) % year is not divisible by 400
tf = false; % it is a common year
else
tf = true; % it is a leap year
end
end close all;
clear all;
clc;
Datafiles = fileDatastore("temp_summary.12*.txt","ReadFcn",@readMonth,"UniformRead",true);
dataAll = readall(Datafiles);
dataAll.Year = year(dataAll.Day);
dataAll.Month = month(dataAll.Day);
dataAll.DD = day(dataAll.Day);
LY = (dataAll.Month(:)==2 & dataAll.DD(:)==29);
dataAll(LY,:) = [];
% Unstack variables
minT_tbl = unstack(dataAll,"MinT","Year","GroupingVariables", ["Month","DD"],"VariableNamingRule","preserve")
maxT_tbl = unstack(dataAll,"MaxT","Year","GroupingVariables", ["Month","DD"],"VariableNamingRule","preserve")
yrs =str2double(minT_tbl.Properties.VariableNames(3:end))’;
% find min
[Tmin,idxMn] = min(minT_tbl{:,3:end},[],2,’omitnan’);
Tmin_yr = yrs(idxMn);
% find max
[Tmax,idxMx] = max(maxT_tbl{:,3:end},[],2,’omitnan’);
Tmax_yr = yrs(idxMx);
% find low high
[lowTMax,idxMx] = min(maxT_tbl{:,3:end},[],2,’omitnan’);
LowTMax_yr = yrs(idxMx);
% find high low
[highlowTMn,idxMn] = max(minT_tbl{:,3:end},[],2,’omitnan’);
HighLowT_yr = yrs(idxMn);
% find avg high
AvgTMx = round(mean(table2array(maxT_tbl(:,3:end)),2,’omitnan’));
% find avg low
AvgTMn = round(mean(table2array(minT_tbl(:,3:end)),2,’omitnan’));
% Results
tempTbl = [maxT_tbl(:,["Month","DD"]), table(Tmax,Tmax_yr,AvgTMx,lowTMax,LowTMax_yr,Tmin,Tmin_yr,AvgTMn,highlowTMn,HighLowT_yr)]
tempTbl2 = splitvars(tempTbl)
FID = fopen(‘Meda 12 Temperature Climatology.txt’,’w’);
report_date = datetime(‘now’,’format’,’yyyy-MM-dd HH:MM’);
fprintf(FID,’Meda 12 Temperature Climatology at %s n’, report_date);
fprintf(FID,"Month DD Temp Max (°F) Tmax_yr AvgTMax (°F) lowTMax (°F) LowTMax_yr TempMin (°F) TMin_yr AvgTMin (°F) HighlowTMin (°F) HighlowT_yr n");
fprintf(FID,’%3d %6d %7d %14d %11d %11d %15d %11d %13d %10d %13d %17d n’, tempTbl2{:,1:end}’);
fclose(FID);
winopen(‘Meda 12 Temperature Climatology.txt’)
function Tbl = readMonth(filename)
opts = detectImportOptions(filename);
opts.ConsecutiveDelimitersRule = ‘join’;
opts.MissingRule = ‘omitvar’;
opts = setvartype(opts,’double’);
opts.VariableNames = ["Day","MaxT","MinT","AvgT"];
Tbl = readtable(filename,opts);
Tbl = standardizeMissing(Tbl,{999,’N/A’},"DataVariables",{‘MaxT’,’MinT’,’AvgT’});
Tbl = standardizeMissing(Tbl,{-99,’N/A’},"DataVariables",{‘MaxT’,’MinT’,’AvgT’});
[~,basename] = fileparts(filename);
% use the base file name, not the full file name:
d = str2double(extract(basename,digitsPattern));
if ~leapyear(d(3)) && d(2) == 2 % February of a non-leap-year
Tbl(Tbl.Day == 29,:) = []; % remove the 29th day data, if any
end
Tbl.Day = datetime(d(3),d(2),Tbl.Day);
end
function tf = leapyear(y)
if mod(y,4) % year is not divisible by 4
tf = false; % it is a common year
elseif mod(y,100) % year is not divisible by 100
tf = true; % it is a leap year
elseif mod(y,400) % year is not divisible by 400
tf = false; % it is a common year
else
tf = true; % it is a leap year
end
end python, matlab code MATLAB Answers — New Questions
Even though I finished the course 100% the certification ,progress report and in my courses it shows as 0% , why is it so? the course is “simulink Onramp”
Warning: File "/tmp/simulinkselfpaced/SimulinkOnramp.slx" is missing, which will prevent you from saving this model properly. If the file moved, then close the model and open
Like this text is coming in command window of MatLabWarning: File "/tmp/simulinkselfpaced/SimulinkOnramp.slx" is missing, which will prevent you from saving this model properly. If the file moved, then close the model and open
Like this text is coming in command window of MatLab Warning: File "/tmp/simulinkselfpaced/SimulinkOnramp.slx" is missing, which will prevent you from saving this model properly. If the file moved, then close the model and open
Like this text is coming in command window of MatLab mathworks, course_no_progress_updation MATLAB Answers — New Questions
lsqcurvefit “Function value and YDATA sizes are not equal” for a complicated fitting function
Hi all, I have some experimental data to be fitted to a function that is quite complicated (refer to the attached picture). And I kept getting the message that the function size and YDATA size are not equal. How do I solve this?
clear; clc
load Steady_State_Data.mat % this contains the wavelength of light and absorbance of substrate and sample
% Fundamental constants
h = 4.0135667696*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
% Clean up of data to select range of values
Absorbance = log10(T_substrate./T_sample);
E = (h*c./(Lambda*10^-9));
e = E >= 0 & E <= 2.0; % returns boolean value of the indices that satisfies the logical condition defined above
A = find(e); % gives indices that are non-zero
N = length(A); % no. of elements that are non-zero
n = length(E) + 1;
% Data for fitting
E_p = E(n-N:167);
Abs = Absorbance(n-N:167);
function F = EM_SS(p, e_p)
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
(integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
126*p(5)^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1)) + …
p(2)*(2*pi*p(4)^3/2)*1/p(6)*(…
(1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
(1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
(1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
(1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
(1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
(1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
(1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6)));
end
end
% Initial parameter guess and bounds
lb = []; ub = [];
p0 = [0.13 0.1 1.6 0.05 3 1]; % refer to the next line for their order
% p0 = [A1 A2 Eg Eb R g]
% choose between different algorithm of lsqcurvefit (3C1, comment those lines that are not choosen, if not, matlab will take the last line of "optim_lsq" by default)
optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘levenberg-marquardt’);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘trust-region-reflective’);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘interior-point’);
% fminunc
% optim_fminunc = optimsoptions(‘fminunc’, ‘Algorithm’, ‘Quasi-Newton’);
% solver
[p, resnorm, residual, exitflag, output, jacobian] = lsqcurvefit(@EM_SS, p0, E_p, Abs);
% p = lsqcurvefit(@EM_SS, p0, E_p, Abs);
% Plot command
plot(E_p, Abs, ‘o’)
hold on
% plot(E_p, p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
% (integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
% 126*p(5)^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1)) + …
% p(2)*(2*pi*p(4)^3/2)*1/p(6)*(…
% (1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
% (1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
% (1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
% (1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
% (1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
% (1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
% (1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6))))
plot(E_p, EM_SS(E_p, p))
xlabel(‘Probe energy (eV)’)
ylabel(‘Absorbance.O.D’)
legend(‘Experimental Data’, ‘Fitted Curve’)
hold off
% Parameter values (refer to command window)
p1 = p(1,1);
p2 = p(1,2);
p3 = p(1,3);
p4 = p(1,4);
p5 = p(1,5);
p6 = p(1,6);
X1 = [‘ A1 = ‘, num2str(p1)];
X2 = [‘ A2 = ‘, num2str(p2)];
X3 = [‘ Eg = ‘, num2str(p3)];
X4 = [‘ Eb = ‘, num2str(p4)];
X5 = [‘ R = ‘, num2str(p5)];
X6 = [‘ g = ‘, num2str(p6)];
disp(X1);
disp(X2);
disp(X3);
disp(X4);
disp(X5);
disp(X6);Hi all, I have some experimental data to be fitted to a function that is quite complicated (refer to the attached picture). And I kept getting the message that the function size and YDATA size are not equal. How do I solve this?
clear; clc
load Steady_State_Data.mat % this contains the wavelength of light and absorbance of substrate and sample
% Fundamental constants
h = 4.0135667696*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
% Clean up of data to select range of values
Absorbance = log10(T_substrate./T_sample);
E = (h*c./(Lambda*10^-9));
e = E >= 0 & E <= 2.0; % returns boolean value of the indices that satisfies the logical condition defined above
A = find(e); % gives indices that are non-zero
N = length(A); % no. of elements that are non-zero
n = length(E) + 1;
% Data for fitting
E_p = E(n-N:167);
Abs = Absorbance(n-N:167);
function F = EM_SS(p, e_p)
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
(integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
126*p(5)^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1)) + …
p(2)*(2*pi*p(4)^3/2)*1/p(6)*(…
(1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
(1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
(1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
(1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
(1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
(1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
(1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6)));
end
end
% Initial parameter guess and bounds
lb = []; ub = [];
p0 = [0.13 0.1 1.6 0.05 3 1]; % refer to the next line for their order
% p0 = [A1 A2 Eg Eb R g]
% choose between different algorithm of lsqcurvefit (3C1, comment those lines that are not choosen, if not, matlab will take the last line of "optim_lsq" by default)
optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘levenberg-marquardt’);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘trust-region-reflective’);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘interior-point’);
% fminunc
% optim_fminunc = optimsoptions(‘fminunc’, ‘Algorithm’, ‘Quasi-Newton’);
% solver
[p, resnorm, residual, exitflag, output, jacobian] = lsqcurvefit(@EM_SS, p0, E_p, Abs);
% p = lsqcurvefit(@EM_SS, p0, E_p, Abs);
% Plot command
plot(E_p, Abs, ‘o’)
hold on
% plot(E_p, p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
% (integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
% 126*p(5)^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1)) + …
% p(2)*(2*pi*p(4)^3/2)*1/p(6)*(…
% (1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
% (1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
% (1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
% (1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
% (1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
% (1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
% (1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6))))
plot(E_p, EM_SS(E_p, p))
xlabel(‘Probe energy (eV)’)
ylabel(‘Absorbance.O.D’)
legend(‘Experimental Data’, ‘Fitted Curve’)
hold off
% Parameter values (refer to command window)
p1 = p(1,1);
p2 = p(1,2);
p3 = p(1,3);
p4 = p(1,4);
p5 = p(1,5);
p6 = p(1,6);
X1 = [‘ A1 = ‘, num2str(p1)];
X2 = [‘ A2 = ‘, num2str(p2)];
X3 = [‘ Eg = ‘, num2str(p3)];
X4 = [‘ Eb = ‘, num2str(p4)];
X5 = [‘ R = ‘, num2str(p5)];
X6 = [‘ g = ‘, num2str(p6)];
disp(X1);
disp(X2);
disp(X3);
disp(X4);
disp(X5);
disp(X6); Hi all, I have some experimental data to be fitted to a function that is quite complicated (refer to the attached picture). And I kept getting the message that the function size and YDATA size are not equal. How do I solve this?
clear; clc
load Steady_State_Data.mat % this contains the wavelength of light and absorbance of substrate and sample
% Fundamental constants
h = 4.0135667696*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
% Clean up of data to select range of values
Absorbance = log10(T_substrate./T_sample);
E = (h*c./(Lambda*10^-9));
e = E >= 0 & E <= 2.0; % returns boolean value of the indices that satisfies the logical condition defined above
A = find(e); % gives indices that are non-zero
N = length(A); % no. of elements that are non-zero
n = length(E) + 1;
% Data for fitting
E_p = E(n-N:167);
Abs = Absorbance(n-N:167);
function F = EM_SS(p, e_p)
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
(integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
126*p(5)^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1)) + …
p(2)*(2*pi*p(4)^3/2)*1/p(6)*(…
(1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
(1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
(1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
(1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
(1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
(1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
(1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6)));
end
end
% Initial parameter guess and bounds
lb = []; ub = [];
p0 = [0.13 0.1 1.6 0.05 3 1]; % refer to the next line for their order
% p0 = [A1 A2 Eg Eb R g]
% choose between different algorithm of lsqcurvefit (3C1, comment those lines that are not choosen, if not, matlab will take the last line of "optim_lsq" by default)
optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘levenberg-marquardt’);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘trust-region-reflective’);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘interior-point’);
% fminunc
% optim_fminunc = optimsoptions(‘fminunc’, ‘Algorithm’, ‘Quasi-Newton’);
% solver
[p, resnorm, residual, exitflag, output, jacobian] = lsqcurvefit(@EM_SS, p0, E_p, Abs);
% p = lsqcurvefit(@EM_SS, p0, E_p, Abs);
% Plot command
plot(E_p, Abs, ‘o’)
hold on
% plot(E_p, p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
% (integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
% 126*p(5)^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1)) + …
% p(2)*(2*pi*p(4)^3/2)*1/p(6)*(…
% (1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
% (1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
% (1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
% (1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
% (1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
% (1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
% (1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6))))
plot(E_p, EM_SS(E_p, p))
xlabel(‘Probe energy (eV)’)
ylabel(‘Absorbance.O.D’)
legend(‘Experimental Data’, ‘Fitted Curve’)
hold off
% Parameter values (refer to command window)
p1 = p(1,1);
p2 = p(1,2);
p3 = p(1,3);
p4 = p(1,4);
p5 = p(1,5);
p6 = p(1,6);
X1 = [‘ A1 = ‘, num2str(p1)];
X2 = [‘ A2 = ‘, num2str(p2)];
X3 = [‘ Eg = ‘, num2str(p3)];
X4 = [‘ Eb = ‘, num2str(p4)];
X5 = [‘ R = ‘, num2str(p5)];
X6 = [‘ g = ‘, num2str(p6)];
disp(X1);
disp(X2);
disp(X3);
disp(X4);
disp(X5);
disp(X6); curve fitting MATLAB Answers — New Questions
Multiple sequences for Neural State-Space Model training and different sampling times
Hi all,
I have some doubts about Neural State-Space Models.
1) I would like to train such a model using different observations (or tests). In other words, I have time sequences measured in different experiments and I would like to use them to train the model. From the examples currently online, I could not figure out how to do this, since it seems to me that the training data are always represented by a single time sequence.
2) Suppose the time sequences I want to train the model with have a sampling time given as d_t. I want to use the Neural State-Space Model that I identify with this data in Simulink. I can do this using just the dedicated Neural State-Space Model block. Suppose, however, that I want to run simulations using this model in Simulink with sample times to my preference. I am aware of rate transition blocks, but can they do the trick for me for this type of problem? In other words, does the Simulink block of the Neural State-Space Model allow me to work with other sampling times, or am I constrained to use the model with sampling times equal to that of the time series with which I have trained the model (thus what has been referred to as d_t)?
Thank you in advance for the support!
Best regards,
MarcoHi all,
I have some doubts about Neural State-Space Models.
1) I would like to train such a model using different observations (or tests). In other words, I have time sequences measured in different experiments and I would like to use them to train the model. From the examples currently online, I could not figure out how to do this, since it seems to me that the training data are always represented by a single time sequence.
2) Suppose the time sequences I want to train the model with have a sampling time given as d_t. I want to use the Neural State-Space Model that I identify with this data in Simulink. I can do this using just the dedicated Neural State-Space Model block. Suppose, however, that I want to run simulations using this model in Simulink with sample times to my preference. I am aware of rate transition blocks, but can they do the trick for me for this type of problem? In other words, does the Simulink block of the Neural State-Space Model allow me to work with other sampling times, or am I constrained to use the model with sampling times equal to that of the time series with which I have trained the model (thus what has been referred to as d_t)?
Thank you in advance for the support!
Best regards,
Marco Hi all,
I have some doubts about Neural State-Space Models.
1) I would like to train such a model using different observations (or tests). In other words, I have time sequences measured in different experiments and I would like to use them to train the model. From the examples currently online, I could not figure out how to do this, since it seems to me that the training data are always represented by a single time sequence.
2) Suppose the time sequences I want to train the model with have a sampling time given as d_t. I want to use the Neural State-Space Model that I identify with this data in Simulink. I can do this using just the dedicated Neural State-Space Model block. Suppose, however, that I want to run simulations using this model in Simulink with sample times to my preference. I am aware of rate transition blocks, but can they do the trick for me for this type of problem? In other words, does the Simulink block of the Neural State-Space Model allow me to work with other sampling times, or am I constrained to use the model with sampling times equal to that of the time series with which I have trained the model (thus what has been referred to as d_t)?
Thank you in advance for the support!
Best regards,
Marco neural state-space models, system identification, machine learning, deep learning, reduced order modelling, simulation MATLAB Answers — New Questions
median of grouped frequency data
Given the data below
calculate the median of the data in MATLAB
I have the code below
class_intervals = [420 430; 430 440; 440 450; 450 460; 460 470; 470 480; 480 490; 490 500];
frequencies = [336, 2112, 2336, 1074, 1553, 1336, 736, 85];
% Calculate the cumulative frequencies
cum_frequencies = cumsum(frequencies)
% Calculate the total number of observations
N = sum(frequencies);
% Find the median class (where cumulative frequency exceeds N/2)
median_class_index = find(cum_frequencies >= N/2, 1)
% Extract the lower boundary, frequency, and cumulative frequency of the class before the median class
L = class_intervals(median_class_index, 1) % lower boundary of the median class
f = frequencies(median_class_index) % frequency of the median class
if median_class_index == 1
cf = 0; % cumulative frequency before the median class
else
cf = cum_frequencies(median_class_index – 1) % cumulative frequency before the median class
end
% Calculate the width of the median class interval
h = class_intervals(median_class_index, 2) – class_intervals(median_class_index, 1)
% Calculate the median using the formula
median = L + ((N/2 – cf) / f) * h
However I was wondering if instead of calculating it manually is there any inbuilt function in MATLAB to calculate median of grouped data.Given the data below
calculate the median of the data in MATLAB
I have the code below
class_intervals = [420 430; 430 440; 440 450; 450 460; 460 470; 470 480; 480 490; 490 500];
frequencies = [336, 2112, 2336, 1074, 1553, 1336, 736, 85];
% Calculate the cumulative frequencies
cum_frequencies = cumsum(frequencies)
% Calculate the total number of observations
N = sum(frequencies);
% Find the median class (where cumulative frequency exceeds N/2)
median_class_index = find(cum_frequencies >= N/2, 1)
% Extract the lower boundary, frequency, and cumulative frequency of the class before the median class
L = class_intervals(median_class_index, 1) % lower boundary of the median class
f = frequencies(median_class_index) % frequency of the median class
if median_class_index == 1
cf = 0; % cumulative frequency before the median class
else
cf = cum_frequencies(median_class_index – 1) % cumulative frequency before the median class
end
% Calculate the width of the median class interval
h = class_intervals(median_class_index, 2) – class_intervals(median_class_index, 1)
% Calculate the median using the formula
median = L + ((N/2 – cf) / f) * h
However I was wondering if instead of calculating it manually is there any inbuilt function in MATLAB to calculate median of grouped data. Given the data below
calculate the median of the data in MATLAB
I have the code below
class_intervals = [420 430; 430 440; 440 450; 450 460; 460 470; 470 480; 480 490; 490 500];
frequencies = [336, 2112, 2336, 1074, 1553, 1336, 736, 85];
% Calculate the cumulative frequencies
cum_frequencies = cumsum(frequencies)
% Calculate the total number of observations
N = sum(frequencies);
% Find the median class (where cumulative frequency exceeds N/2)
median_class_index = find(cum_frequencies >= N/2, 1)
% Extract the lower boundary, frequency, and cumulative frequency of the class before the median class
L = class_intervals(median_class_index, 1) % lower boundary of the median class
f = frequencies(median_class_index) % frequency of the median class
if median_class_index == 1
cf = 0; % cumulative frequency before the median class
else
cf = cum_frequencies(median_class_index – 1) % cumulative frequency before the median class
end
% Calculate the width of the median class interval
h = class_intervals(median_class_index, 2) – class_intervals(median_class_index, 1)
% Calculate the median using the formula
median = L + ((N/2 – cf) / f) * h
However I was wondering if instead of calculating it manually is there any inbuilt function in MATLAB to calculate median of grouped data. descriptive statistics MATLAB Answers — New Questions
Shapley values for newff model
Hi there, I trained a BP nerual network using newff function, and want to obtain its Shapley values and swarmchart graph. But I have got the following error:
Code:
P = [2 3 1;3 4 5;1 3 4;4 6 7;2 7 3]’;
T = [1 2 3 4 5];
net=newff(P,T,5,{‘tansig’ ‘purelin’},’trainlm’);
[net,tr]=train(net,P,T);
queryPoint = P(:,1);
explainer1 = shapley(net,P,’QueryPoint’,queryPoint);
Error:
Error using shapley (line 233)
Blackbox model must be a classification model, regression model, or function handle
Error in untitled (line 10)
explainer1 = shapley(net,P,’QueryPoint’,queryPoint);Hi there, I trained a BP nerual network using newff function, and want to obtain its Shapley values and swarmchart graph. But I have got the following error:
Code:
P = [2 3 1;3 4 5;1 3 4;4 6 7;2 7 3]’;
T = [1 2 3 4 5];
net=newff(P,T,5,{‘tansig’ ‘purelin’},’trainlm’);
[net,tr]=train(net,P,T);
queryPoint = P(:,1);
explainer1 = shapley(net,P,’QueryPoint’,queryPoint);
Error:
Error using shapley (line 233)
Blackbox model must be a classification model, regression model, or function handle
Error in untitled (line 10)
explainer1 = shapley(net,P,’QueryPoint’,queryPoint); Hi there, I trained a BP nerual network using newff function, and want to obtain its Shapley values and swarmchart graph. But I have got the following error:
Code:
P = [2 3 1;3 4 5;1 3 4;4 6 7;2 7 3]’;
T = [1 2 3 4 5];
net=newff(P,T,5,{‘tansig’ ‘purelin’},’trainlm’);
[net,tr]=train(net,P,T);
queryPoint = P(:,1);
explainer1 = shapley(net,P,’QueryPoint’,queryPoint);
Error:
Error using shapley (line 233)
Blackbox model must be a classification model, regression model, or function handle
Error in untitled (line 10)
explainer1 = shapley(net,P,’QueryPoint’,queryPoint); shapley MATLAB Answers — New Questions
PSAT Compatibility issues for MATLAB
Hello Guys,
I have been trying to run PSAT for MATLAB, however even the example files are not working for me. Has the code become obsolete? Is the PSAT no longer working?
I tried the latest available version for PSAT(2.1.11) with MATLAB R2024a and R2018a but both did not work.
This is the error message which gets generated when I try to load an example .m file from the tests folder and hit power flow button.
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in fm_wcall (line 49)
count = fprintf(fid,’function fm_call(flag)nn’);
Error in fm_spf (line 41)
fm_wcall;
Error in fm_set (line 721)
fm_spf
Error while evaluating UIControl Callback
For the .mdl example file, it is generating the following error
Simulink Model Conversion
Simulink File <d_hvdc.mdl>.
Loading Simulink Model
Error using delete
Cannot access method ‘delete’ in class ‘matlab.ui.Root’.
Error in fm_bar (line 41)
if ishandle(Hdl.bar), delete(Hdl.bar); end
Error in sim2psat (line 133)
fm_bar open
Error in fm_dirset (line 474)
check = sim2psat(filename,pwd);
Error in fm_dirset (line 563)
check = fm_dirset(‘convert’);
Error using uiwait (line 81)
Error while evaluating UIControl Callback.
I made sure to unzip the folder correctly and even add to path, but still the problem persists.
Any help would be greatly benefical.
Best RegardsHello Guys,
I have been trying to run PSAT for MATLAB, however even the example files are not working for me. Has the code become obsolete? Is the PSAT no longer working?
I tried the latest available version for PSAT(2.1.11) with MATLAB R2024a and R2018a but both did not work.
This is the error message which gets generated when I try to load an example .m file from the tests folder and hit power flow button.
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in fm_wcall (line 49)
count = fprintf(fid,’function fm_call(flag)nn’);
Error in fm_spf (line 41)
fm_wcall;
Error in fm_set (line 721)
fm_spf
Error while evaluating UIControl Callback
For the .mdl example file, it is generating the following error
Simulink Model Conversion
Simulink File <d_hvdc.mdl>.
Loading Simulink Model
Error using delete
Cannot access method ‘delete’ in class ‘matlab.ui.Root’.
Error in fm_bar (line 41)
if ishandle(Hdl.bar), delete(Hdl.bar); end
Error in sim2psat (line 133)
fm_bar open
Error in fm_dirset (line 474)
check = sim2psat(filename,pwd);
Error in fm_dirset (line 563)
check = fm_dirset(‘convert’);
Error using uiwait (line 81)
Error while evaluating UIControl Callback.
I made sure to unzip the folder correctly and even add to path, but still the problem persists.
Any help would be greatly benefical.
Best Regards Hello Guys,
I have been trying to run PSAT for MATLAB, however even the example files are not working for me. Has the code become obsolete? Is the PSAT no longer working?
I tried the latest available version for PSAT(2.1.11) with MATLAB R2024a and R2018a but both did not work.
This is the error message which gets generated when I try to load an example .m file from the tests folder and hit power flow button.
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in fm_wcall (line 49)
count = fprintf(fid,’function fm_call(flag)nn’);
Error in fm_spf (line 41)
fm_wcall;
Error in fm_set (line 721)
fm_spf
Error while evaluating UIControl Callback
For the .mdl example file, it is generating the following error
Simulink Model Conversion
Simulink File <d_hvdc.mdl>.
Loading Simulink Model
Error using delete
Cannot access method ‘delete’ in class ‘matlab.ui.Root’.
Error in fm_bar (line 41)
if ishandle(Hdl.bar), delete(Hdl.bar); end
Error in sim2psat (line 133)
fm_bar open
Error in fm_dirset (line 474)
check = sim2psat(filename,pwd);
Error in fm_dirset (line 563)
check = fm_dirset(‘convert’);
Error using uiwait (line 81)
Error while evaluating UIControl Callback.
I made sure to unzip the folder correctly and even add to path, but still the problem persists.
Any help would be greatly benefical.
Best Regards psat, compatibility MATLAB Answers — New Questions
Inverse dynamics block to forward dynamics block
Hello, I am currently facing an issue related to the joint positions of a 6-axis robotic arm. My objective is to visualize these joint accelerations without using a controller(That will be done later). Here’s my approach: I generate a trajectory using a minimum jerk polynomial trajectory, obtaining joint positions (q), velocities (qd), and accelerations (qdd). I then use these values along with an external force (fexterior) as inputs for the Inverse Dynamics block, resulting in joint torques.
Now, with these obtained joint torques, along with the initial joint positions (q), velocities (qd), and the external force (fext) used earlier, I attempt to regenerate the joint positions using the Forward Dynamics block. However, I observe that the joint accelerations remain constant even when I vary the external force (Fext). This is perplexing, especially considering that when I use the Inverse Dynamics block with different Fext values, I obtain distinct joint torques for each payload. Yet, the results from the Forward Dynamics block remain the same.
Could you provide insights into why the joint accelerations from the Forward Dynamics block are not varying with changes in the external force, despite the distinct joint torques obtained from the Inverse Dynamics block for different payloads? Your assistance is highly appreciated. Thank you!Hello, I am currently facing an issue related to the joint positions of a 6-axis robotic arm. My objective is to visualize these joint accelerations without using a controller(That will be done later). Here’s my approach: I generate a trajectory using a minimum jerk polynomial trajectory, obtaining joint positions (q), velocities (qd), and accelerations (qdd). I then use these values along with an external force (fexterior) as inputs for the Inverse Dynamics block, resulting in joint torques.
Now, with these obtained joint torques, along with the initial joint positions (q), velocities (qd), and the external force (fext) used earlier, I attempt to regenerate the joint positions using the Forward Dynamics block. However, I observe that the joint accelerations remain constant even when I vary the external force (Fext). This is perplexing, especially considering that when I use the Inverse Dynamics block with different Fext values, I obtain distinct joint torques for each payload. Yet, the results from the Forward Dynamics block remain the same.
Could you provide insights into why the joint accelerations from the Forward Dynamics block are not varying with changes in the external force, despite the distinct joint torques obtained from the Inverse Dynamics block for different payloads? Your assistance is highly appreciated. Thank you! Hello, I am currently facing an issue related to the joint positions of a 6-axis robotic arm. My objective is to visualize these joint accelerations without using a controller(That will be done later). Here’s my approach: I generate a trajectory using a minimum jerk polynomial trajectory, obtaining joint positions (q), velocities (qd), and accelerations (qdd). I then use these values along with an external force (fexterior) as inputs for the Inverse Dynamics block, resulting in joint torques.
Now, with these obtained joint torques, along with the initial joint positions (q), velocities (qd), and the external force (fext) used earlier, I attempt to regenerate the joint positions using the Forward Dynamics block. However, I observe that the joint accelerations remain constant even when I vary the external force (Fext). This is perplexing, especially considering that when I use the Inverse Dynamics block with different Fext values, I obtain distinct joint torques for each payload. Yet, the results from the Forward Dynamics block remain the same.
Could you provide insights into why the joint accelerations from the Forward Dynamics block are not varying with changes in the external force, despite the distinct joint torques obtained from the Inverse Dynamics block for different payloads? Your assistance is highly appreciated. Thank you! simulink MATLAB Answers — New Questions
What does x(1,:) do in MATLAB ?
What does x(1,:) do in MATLAB ?
eg:
at = sqrt(Po)*exp(-0.5*(1+i*C)*(tau./t0).^(2*m))
a0 = fft(at(1,:));
what does at(1,:) do here ?What does x(1,:) do in MATLAB ?
eg:
at = sqrt(Po)*exp(-0.5*(1+i*C)*(tau./t0).^(2*m))
a0 = fft(at(1,:));
what does at(1,:) do here ? What does x(1,:) do in MATLAB ?
eg:
at = sqrt(Po)*exp(-0.5*(1+i*C)*(tau./t0).^(2*m))
a0 = fft(at(1,:));
what does at(1,:) do here ? syntax MATLAB Answers — New Questions
Unrecognized function or variable ‘del’.
n=0;
>> for del=0.0:0.4:pi
n=n+1;
pe(n)=1.2*sin(del);n=0;
>> for del=0.0:0.4:pi
n=n+1;
pe(n)=1.2*sin(del); n=0;
>> for del=0.0:0.4:pi
n=n+1;
pe(n)=1.2*sin(del); loop MATLAB Answers — New Questions
result spectrogram from lowpass filter still pass frequency above the treshold
I am trying use lowpass filter to my time series data and then i perform spectrogram to check wheater the signal still containing freq above the treshold or not.
clear all, clc, close all
yori=load("HHN__20150101T000000Z__20150102T000000Z.DAT");
y=lowpass(yori,10,100);
Nspec=256;
wspec=hamming(Nspec);
Noverlap=Nspec/2;
fs=100;
subplot 211
[S,F,T,P]=spectrogram(yori,wspec,Noverlap,Nspec,fs,’xaxis’);
imagesc(T/(60*60),F,10*log10(P));
axis xy, title ("spectogram comp:HHN filter:NO")
ylabel(‘Frequency(Hz)’)
subplot 212
[S,F,T,P]=spectrogram(y,wspec,Noverlap,Nspec,fs,’xaxis’);
imagesc(T/(60*60),F,10*log10(P));
axis xy, title ("spectogram comp:HHN filter:YES (lowpass 10Hz")
ylabel(‘Frequency(Hz)’)
Here my code, and the spectrogram shows that signal still contain freq above 10hz (that I don’t want to pass). I don’t understand why this happened? can someone give me suggestion to lowpass 10Hz signal? Thanks in advanceI am trying use lowpass filter to my time series data and then i perform spectrogram to check wheater the signal still containing freq above the treshold or not.
clear all, clc, close all
yori=load("HHN__20150101T000000Z__20150102T000000Z.DAT");
y=lowpass(yori,10,100);
Nspec=256;
wspec=hamming(Nspec);
Noverlap=Nspec/2;
fs=100;
subplot 211
[S,F,T,P]=spectrogram(yori,wspec,Noverlap,Nspec,fs,’xaxis’);
imagesc(T/(60*60),F,10*log10(P));
axis xy, title ("spectogram comp:HHN filter:NO")
ylabel(‘Frequency(Hz)’)
subplot 212
[S,F,T,P]=spectrogram(y,wspec,Noverlap,Nspec,fs,’xaxis’);
imagesc(T/(60*60),F,10*log10(P));
axis xy, title ("spectogram comp:HHN filter:YES (lowpass 10Hz")
ylabel(‘Frequency(Hz)’)
Here my code, and the spectrogram shows that signal still contain freq above 10hz (that I don’t want to pass). I don’t understand why this happened? can someone give me suggestion to lowpass 10Hz signal? Thanks in advance I am trying use lowpass filter to my time series data and then i perform spectrogram to check wheater the signal still containing freq above the treshold or not.
clear all, clc, close all
yori=load("HHN__20150101T000000Z__20150102T000000Z.DAT");
y=lowpass(yori,10,100);
Nspec=256;
wspec=hamming(Nspec);
Noverlap=Nspec/2;
fs=100;
subplot 211
[S,F,T,P]=spectrogram(yori,wspec,Noverlap,Nspec,fs,’xaxis’);
imagesc(T/(60*60),F,10*log10(P));
axis xy, title ("spectogram comp:HHN filter:NO")
ylabel(‘Frequency(Hz)’)
subplot 212
[S,F,T,P]=spectrogram(y,wspec,Noverlap,Nspec,fs,’xaxis’);
imagesc(T/(60*60),F,10*log10(P));
axis xy, title ("spectogram comp:HHN filter:YES (lowpass 10Hz")
ylabel(‘Frequency(Hz)’)
Here my code, and the spectrogram shows that signal still contain freq above 10hz (that I don’t want to pass). I don’t understand why this happened? can someone give me suggestion to lowpass 10Hz signal? Thanks in advance lowpass, spectrogram MATLAB Answers — New Questions
The verify statement criteria/ error message is not appearing in simulink test report.
Hi,
I am using simulink test to test my model. I am using simulink test sequency block and adding verify() to assess criteria. I want verify statement and actual result to appear in simulink test report using simulink test manager. I am using label inside verify() so that simulink test manager captures that. Label is appearing . But assessment criteria and actual result is not appearing in test report. how it is possible to add verify criteria and actual result value in the test report. for example:
verify(x==y,’SimulinkTest:X_equal_Y’,’actual result = %d, %d’x,y);
and then what appears in the report is below image which does not tell much about the test.
what I want to appear is below text:
x==y , SimulinkTest:X_equal_Y , Actual result= 3,5
no verify statement nor the error message appear in the report. It is really frustating that it does not appear in the report.
Thanks,
SomdutHi,
I am using simulink test to test my model. I am using simulink test sequency block and adding verify() to assess criteria. I want verify statement and actual result to appear in simulink test report using simulink test manager. I am using label inside verify() so that simulink test manager captures that. Label is appearing . But assessment criteria and actual result is not appearing in test report. how it is possible to add verify criteria and actual result value in the test report. for example:
verify(x==y,’SimulinkTest:X_equal_Y’,’actual result = %d, %d’x,y);
and then what appears in the report is below image which does not tell much about the test.
what I want to appear is below text:
x==y , SimulinkTest:X_equal_Y , Actual result= 3,5
no verify statement nor the error message appear in the report. It is really frustating that it does not appear in the report.
Thanks,
Somdut Hi,
I am using simulink test to test my model. I am using simulink test sequency block and adding verify() to assess criteria. I want verify statement and actual result to appear in simulink test report using simulink test manager. I am using label inside verify() so that simulink test manager captures that. Label is appearing . But assessment criteria and actual result is not appearing in test report. how it is possible to add verify criteria and actual result value in the test report. for example:
verify(x==y,’SimulinkTest:X_equal_Y’,’actual result = %d, %d’x,y);
and then what appears in the report is below image which does not tell much about the test.
what I want to appear is below text:
x==y , SimulinkTest:X_equal_Y , Actual result= 3,5
no verify statement nor the error message appear in the report. It is really frustating that it does not appear in the report.
Thanks,
Somdut simulink test, simulink report, simulink test manager, verify, test sequence MATLAB Answers — New Questions
App Designer – elements in radio button group change position on opening app designer
I have an app that has a radio button group that is added to a grid layout. Every time I open App Designer, the buttons (and text) within the radio button group change position. More specifically, the buttons shift down (the bottom value for each button decreases by 4).
This isn’t necessarily an error, but it’s driving me nuts because the buttons shift down and eventually I have to manually move them back up after a couple days. I’m not sure if it’s the way App Designer is initializing or if this is some kind of setting I need to change in MATLAB. It seems like App Designer is running some auto-formatting routine at the end of initialization because after opening up App Designer I see that it has made changes (via the *) without me touching anything.
More details:
App Designer opens on my main laptop screen (1920×1200)
This happens regardless of whether I move the App Designer instance to a different screen or not
I’ve tried changing some of the radio button group properties, but nothing seems to fix the issue.I have an app that has a radio button group that is added to a grid layout. Every time I open App Designer, the buttons (and text) within the radio button group change position. More specifically, the buttons shift down (the bottom value for each button decreases by 4).
This isn’t necessarily an error, but it’s driving me nuts because the buttons shift down and eventually I have to manually move them back up after a couple days. I’m not sure if it’s the way App Designer is initializing or if this is some kind of setting I need to change in MATLAB. It seems like App Designer is running some auto-formatting routine at the end of initialization because after opening up App Designer I see that it has made changes (via the *) without me touching anything.
More details:
App Designer opens on my main laptop screen (1920×1200)
This happens regardless of whether I move the App Designer instance to a different screen or not
I’ve tried changing some of the radio button group properties, but nothing seems to fix the issue. I have an app that has a radio button group that is added to a grid layout. Every time I open App Designer, the buttons (and text) within the radio button group change position. More specifically, the buttons shift down (the bottom value for each button decreases by 4).
This isn’t necessarily an error, but it’s driving me nuts because the buttons shift down and eventually I have to manually move them back up after a couple days. I’m not sure if it’s the way App Designer is initializing or if this is some kind of setting I need to change in MATLAB. It seems like App Designer is running some auto-formatting routine at the end of initialization because after opening up App Designer I see that it has made changes (via the *) without me touching anything.
More details:
App Designer opens on my main laptop screen (1920×1200)
This happens regardless of whether I move the App Designer instance to a different screen or not
I’ve tried changing some of the radio button group properties, but nothing seems to fix the issue. radio-button-group, appdesigner MATLAB Answers — New Questions
I’m a fresher here who has just finished the matlab onramp course but unable is stuck at the practise problem.
Question:Given two input variables r and h, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).And this is my answer:
function SA = func_frosting(r, h)
SA = (pi * r * r) + (2 * pi * r * h);
end
radius = 5;
height = 10;
surfaceArea = func_frosting(radius, height);
disp([‘The surface area of the cake is ‘, num2str(surfaceArea), ]);
But it just passes one of the four code test.Please help.Question:Given two input variables r and h, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).And this is my answer:
function SA = func_frosting(r, h)
SA = (pi * r * r) + (2 * pi * r * h);
end
radius = 5;
height = 10;
surfaceArea = func_frosting(radius, height);
disp([‘The surface area of the cake is ‘, num2str(surfaceArea), ]);
But it just passes one of the four code test.Please help. Question:Given two input variables r and h, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).And this is my answer:
function SA = func_frosting(r, h)
SA = (pi * r * r) + (2 * pi * r * h);
end
radius = 5;
height = 10;
surfaceArea = func_frosting(radius, height);
disp([‘The surface area of the cake is ‘, num2str(surfaceArea), ]);
But it just passes one of the four code test.Please help. function, code test, failed MATLAB Answers — New Questions
How to make a geometry transparent?
Hello brothers. I have a geometry and I want to make it transparent as some entities are disappeared. I have used the following commond but no results. Thank you.
gm=mphgeom(model)
mphviewselection(model,gm, ‘facealpha’, 0.5)Hello brothers. I have a geometry and I want to make it transparent as some entities are disappeared. I have used the following commond but no results. Thank you.
gm=mphgeom(model)
mphviewselection(model,gm, ‘facealpha’, 0.5) Hello brothers. I have a geometry and I want to make it transparent as some entities are disappeared. I have used the following commond but no results. Thank you.
gm=mphgeom(model)
mphviewselection(model,gm, ‘facealpha’, 0.5) transaparency, matlab MATLAB Answers — New Questions
adalm pluto receive example error
I am using 2023a matlab, when trying to run the adalm pluto receive simulink example i get this error:
I don’t really understand what is causing this, if i remember correctly i did run it succesfull a few days ago.I am using 2023a matlab, when trying to run the adalm pluto receive simulink example i get this error:
I don’t really understand what is causing this, if i remember correctly i did run it succesfull a few days ago. I am using 2023a matlab, when trying to run the adalm pluto receive simulink example i get this error:
I don’t really understand what is causing this, if i remember correctly i did run it succesfull a few days ago. error, adalm-pluto, example MATLAB Answers — New Questions
Activation on Linux – MathWorksProductAuthorizer crashes
Have any of you experienced the activation program MathWorksProductAuthorizer crashing on Ubuntu 22.04? I cannot reproduce it on all Ubuntu 22.04 machines, and cannot identify what triggers the crash on that specifific Ubuntu 22.04 workstation either.
The error message is:
The feature at URL:
https://127.0.0.1:31515/ui/install/product_installer_ui/index.html?applicationName=productauthorizer&snc=RT7PDK
has crashed and will exit
The exit status was: TS_ABNORMAL_TERMINATIONHave any of you experienced the activation program MathWorksProductAuthorizer crashing on Ubuntu 22.04? I cannot reproduce it on all Ubuntu 22.04 machines, and cannot identify what triggers the crash on that specifific Ubuntu 22.04 workstation either.
The error message is:
The feature at URL:
https://127.0.0.1:31515/ui/install/product_installer_ui/index.html?applicationName=productauthorizer&snc=RT7PDK
has crashed and will exit
The exit status was: TS_ABNORMAL_TERMINATION Have any of you experienced the activation program MathWorksProductAuthorizer crashing on Ubuntu 22.04? I cannot reproduce it on all Ubuntu 22.04 machines, and cannot identify what triggers the crash on that specifific Ubuntu 22.04 workstation either.
The error message is:
The feature at URL:
https://127.0.0.1:31515/ui/install/product_installer_ui/index.html?applicationName=productauthorizer&snc=RT7PDK
has crashed and will exit
The exit status was: TS_ABNORMAL_TERMINATION activate, linux MATLAB Answers — New Questions