Category: Matlab
Category Archives: Matlab
Coupled ODEs by ode45 and could not get the figures
Hi everyone!
I’ve been learning MATLAB for about six months, so I apologize if I ask any basic questions. In part of my project, I have a system of six coupled ODEs (all functions of t). You can refer to the attached picture for more details.
To obtain the T profile in terms of t, I decided to define the function similarly to how many others do:
function dYdt = complexSystem(t, Y)
Aa = 1e14; % Pre-exponential factor for xa
Ea = 2.24e-19; % Activation energy for xa
Ac = 4e13; % Pre-exponential factor for xc
Ec = 2.03e-19; % Activation energy for xc
As = 1e15; % Pre-exponential factor for xs
Es = 2.24e-19; % Activation energy for xs
Aec = 1e12; % Pre-exponential factor for xec
Eec = 1.4e-19; % Activation energy for xec
Kb = 1.38e-23; % Boltzmann constant
z0 = 0.033; % Initial value for z
ma = 0.13;
ha = 1.714e6;
mc = 0.29;
hca = 3.14e5;
hs = 2.57e5;
C = -3600 * 1.1 * 3.0 * (1-0.12-0.51);
T = Y(1);
Xa = Y(2);
Xc = Y(3);
Xs = Y(4);
Z = Y(5);
Soc = Y(6);
dXadt = -Aa * Xa * exp(-Ea/(Kb*T));
dXcdt = Ac * Xc * exp(1 – Xc) * exp(-Ec / (Kb * T));
dXsdt = -As * Xs * exp((-Z / z0) * (-Es / (Kb * T)));
dZdt = Aa * Xs * exp((-Z / z0) * (-Es / (Kb * T)));
dSocdt = -Aec * (1 – Xc) * Xa * exp(-Eec / (Kb * T));
Qa = -ma * ha * dXadt;
Qc = -mc * hca * dXcdt;
Qs = -ma * hs * dXsdt;
Qec = C * dSocdt;
Q = Qa + Qc + Qs + Qec;
dTdt = Q;
dYdt = [dTdt; dXadt; dXcdt; dXsdt; dZdt; dSocdt];
end
Then, I defined the initial conditions and solved the ODEs using ode45.
% Initial conditions
Y0 = [298; 0.75; 0.04; 0.015; 0.0331; 0]; % [T0; Xa0; Xc0; Xs0; Z0; Soc0]
% Time span
tspan = [0 100000];
% Solve ODEs
[T, Y] = ode45(@(t, Y) complexSystem(t, Y), tspan, Y0);
Lastly, I attempted to plot the results. However, the code took forever to run, and I didn’t get any figures from it.
Could my initial conditions be incorrect? Or are my ODEs not converging?
Thank you so much for your time and help!
figure;
plot(T, Y)
legend(‘T’, ‘X_a’, ‘X_c’, ‘X_s’, ‘Z’, ‘S_{oc}’)
title(‘Solution of Corrected Complex System’)
xlabel(‘Time t’)
ylabel(‘State Variables’)Hi everyone!
I’ve been learning MATLAB for about six months, so I apologize if I ask any basic questions. In part of my project, I have a system of six coupled ODEs (all functions of t). You can refer to the attached picture for more details.
To obtain the T profile in terms of t, I decided to define the function similarly to how many others do:
function dYdt = complexSystem(t, Y)
Aa = 1e14; % Pre-exponential factor for xa
Ea = 2.24e-19; % Activation energy for xa
Ac = 4e13; % Pre-exponential factor for xc
Ec = 2.03e-19; % Activation energy for xc
As = 1e15; % Pre-exponential factor for xs
Es = 2.24e-19; % Activation energy for xs
Aec = 1e12; % Pre-exponential factor for xec
Eec = 1.4e-19; % Activation energy for xec
Kb = 1.38e-23; % Boltzmann constant
z0 = 0.033; % Initial value for z
ma = 0.13;
ha = 1.714e6;
mc = 0.29;
hca = 3.14e5;
hs = 2.57e5;
C = -3600 * 1.1 * 3.0 * (1-0.12-0.51);
T = Y(1);
Xa = Y(2);
Xc = Y(3);
Xs = Y(4);
Z = Y(5);
Soc = Y(6);
dXadt = -Aa * Xa * exp(-Ea/(Kb*T));
dXcdt = Ac * Xc * exp(1 – Xc) * exp(-Ec / (Kb * T));
dXsdt = -As * Xs * exp((-Z / z0) * (-Es / (Kb * T)));
dZdt = Aa * Xs * exp((-Z / z0) * (-Es / (Kb * T)));
dSocdt = -Aec * (1 – Xc) * Xa * exp(-Eec / (Kb * T));
Qa = -ma * ha * dXadt;
Qc = -mc * hca * dXcdt;
Qs = -ma * hs * dXsdt;
Qec = C * dSocdt;
Q = Qa + Qc + Qs + Qec;
dTdt = Q;
dYdt = [dTdt; dXadt; dXcdt; dXsdt; dZdt; dSocdt];
end
Then, I defined the initial conditions and solved the ODEs using ode45.
% Initial conditions
Y0 = [298; 0.75; 0.04; 0.015; 0.0331; 0]; % [T0; Xa0; Xc0; Xs0; Z0; Soc0]
% Time span
tspan = [0 100000];
% Solve ODEs
[T, Y] = ode45(@(t, Y) complexSystem(t, Y), tspan, Y0);
Lastly, I attempted to plot the results. However, the code took forever to run, and I didn’t get any figures from it.
Could my initial conditions be incorrect? Or are my ODEs not converging?
Thank you so much for your time and help!
figure;
plot(T, Y)
legend(‘T’, ‘X_a’, ‘X_c’, ‘X_s’, ‘Z’, ‘S_{oc}’)
title(‘Solution of Corrected Complex System’)
xlabel(‘Time t’)
ylabel(‘State Variables’) Hi everyone!
I’ve been learning MATLAB for about six months, so I apologize if I ask any basic questions. In part of my project, I have a system of six coupled ODEs (all functions of t). You can refer to the attached picture for more details.
To obtain the T profile in terms of t, I decided to define the function similarly to how many others do:
function dYdt = complexSystem(t, Y)
Aa = 1e14; % Pre-exponential factor for xa
Ea = 2.24e-19; % Activation energy for xa
Ac = 4e13; % Pre-exponential factor for xc
Ec = 2.03e-19; % Activation energy for xc
As = 1e15; % Pre-exponential factor for xs
Es = 2.24e-19; % Activation energy for xs
Aec = 1e12; % Pre-exponential factor for xec
Eec = 1.4e-19; % Activation energy for xec
Kb = 1.38e-23; % Boltzmann constant
z0 = 0.033; % Initial value for z
ma = 0.13;
ha = 1.714e6;
mc = 0.29;
hca = 3.14e5;
hs = 2.57e5;
C = -3600 * 1.1 * 3.0 * (1-0.12-0.51);
T = Y(1);
Xa = Y(2);
Xc = Y(3);
Xs = Y(4);
Z = Y(5);
Soc = Y(6);
dXadt = -Aa * Xa * exp(-Ea/(Kb*T));
dXcdt = Ac * Xc * exp(1 – Xc) * exp(-Ec / (Kb * T));
dXsdt = -As * Xs * exp((-Z / z0) * (-Es / (Kb * T)));
dZdt = Aa * Xs * exp((-Z / z0) * (-Es / (Kb * T)));
dSocdt = -Aec * (1 – Xc) * Xa * exp(-Eec / (Kb * T));
Qa = -ma * ha * dXadt;
Qc = -mc * hca * dXcdt;
Qs = -ma * hs * dXsdt;
Qec = C * dSocdt;
Q = Qa + Qc + Qs + Qec;
dTdt = Q;
dYdt = [dTdt; dXadt; dXcdt; dXsdt; dZdt; dSocdt];
end
Then, I defined the initial conditions and solved the ODEs using ode45.
% Initial conditions
Y0 = [298; 0.75; 0.04; 0.015; 0.0331; 0]; % [T0; Xa0; Xc0; Xs0; Z0; Soc0]
% Time span
tspan = [0 100000];
% Solve ODEs
[T, Y] = ode45(@(t, Y) complexSystem(t, Y), tspan, Y0);
Lastly, I attempted to plot the results. However, the code took forever to run, and I didn’t get any figures from it.
Could my initial conditions be incorrect? Or are my ODEs not converging?
Thank you so much for your time and help!
figure;
plot(T, Y)
legend(‘T’, ‘X_a’, ‘X_c’, ‘X_s’, ‘Z’, ‘S_{oc}’)
title(‘Solution of Corrected Complex System’)
xlabel(‘Time t’)
ylabel(‘State Variables’) ode45 MATLAB Answers — New Questions
Trouble With MATLAB Variable Creation
Hello! I would like to dynamically read in data and assign data values from a text file.
Here is the text file:
object crop_image.nii
plane 3
coeff -5.046e-19 3.168e-13 -5.716e-8 0.005 2.746
amax 1
nfact 1
pt .9906
suvr 1
regi 1
Initially, I was reading it in using this block of code (which works).
readin = readlines(insert text file name here);
for i = 1:length(readin)
this = split(readin(i))’;
switch this(1)
case ‘object’
object = this{2};
case ‘plane’
plane = str2double(this{2});
case ‘coeff’
coeff = str2double(this(2:end));
case ‘suvr’
suvr = str2double(this{2});
case ‘amax’
amax = str2double(this{2});
case ‘nfact’
nfact = str2double(this{2});
case ‘pt’
pt = str2double(this{2});
case ‘regi’
regi = str2double(this{2});
otherwise
fprintf(‘Invalid delimiter: %s! Please check your text file.n’, this{1});
return;
end
end
But a huge switch case doesn’t really give polish. I guess it shouldn’t matter if the code works, but still. I’d like it to be more refined.
Oh, yeah, the reason for all the cell array stuff (and for the huge switch case) is because I’ll be running this code (this code is a portion of a much larger script) from Linux. Also, the text file isn’t guaranteed to come in the order of object, plane, coeff, etc., which is why I have the code detect the first word.
Anyway, I thought I could solve my issue using the assignin function, but it’s not working? Here’s what I have so far.
if ismember(this(1), ["object", "plane", "coeff", "suvr", "amax", "nfact", "pt", "regi"])
if isa(this(2), ‘string’)
assignin(‘base’, this(1), this(2));
else
assignin(‘base’, this(1), str2double(this(2:end)));
end
else
fprintf(‘Invalid delimiter: %s! Please check your text file.n’, this(1));
return;
end
I’ve done my best to debug. The code is not skipping over the assignin function. That line of code is executing, but when it executes, nothing happens.
Like, I’ve checked the values of this(1) and this(2) right before the script calls the assignin function. Yes, this(1) equals "object" and this(2) equals the object name, also a string, but nothing shows up when the assignin line of code executes. I don’t get it. Would appreciate any and all suggestions. Thanks.Hello! I would like to dynamically read in data and assign data values from a text file.
Here is the text file:
object crop_image.nii
plane 3
coeff -5.046e-19 3.168e-13 -5.716e-8 0.005 2.746
amax 1
nfact 1
pt .9906
suvr 1
regi 1
Initially, I was reading it in using this block of code (which works).
readin = readlines(insert text file name here);
for i = 1:length(readin)
this = split(readin(i))’;
switch this(1)
case ‘object’
object = this{2};
case ‘plane’
plane = str2double(this{2});
case ‘coeff’
coeff = str2double(this(2:end));
case ‘suvr’
suvr = str2double(this{2});
case ‘amax’
amax = str2double(this{2});
case ‘nfact’
nfact = str2double(this{2});
case ‘pt’
pt = str2double(this{2});
case ‘regi’
regi = str2double(this{2});
otherwise
fprintf(‘Invalid delimiter: %s! Please check your text file.n’, this{1});
return;
end
end
But a huge switch case doesn’t really give polish. I guess it shouldn’t matter if the code works, but still. I’d like it to be more refined.
Oh, yeah, the reason for all the cell array stuff (and for the huge switch case) is because I’ll be running this code (this code is a portion of a much larger script) from Linux. Also, the text file isn’t guaranteed to come in the order of object, plane, coeff, etc., which is why I have the code detect the first word.
Anyway, I thought I could solve my issue using the assignin function, but it’s not working? Here’s what I have so far.
if ismember(this(1), ["object", "plane", "coeff", "suvr", "amax", "nfact", "pt", "regi"])
if isa(this(2), ‘string’)
assignin(‘base’, this(1), this(2));
else
assignin(‘base’, this(1), str2double(this(2:end)));
end
else
fprintf(‘Invalid delimiter: %s! Please check your text file.n’, this(1));
return;
end
I’ve done my best to debug. The code is not skipping over the assignin function. That line of code is executing, but when it executes, nothing happens.
Like, I’ve checked the values of this(1) and this(2) right before the script calls the assignin function. Yes, this(1) equals "object" and this(2) equals the object name, also a string, but nothing shows up when the assignin line of code executes. I don’t get it. Would appreciate any and all suggestions. Thanks. Hello! I would like to dynamically read in data and assign data values from a text file.
Here is the text file:
object crop_image.nii
plane 3
coeff -5.046e-19 3.168e-13 -5.716e-8 0.005 2.746
amax 1
nfact 1
pt .9906
suvr 1
regi 1
Initially, I was reading it in using this block of code (which works).
readin = readlines(insert text file name here);
for i = 1:length(readin)
this = split(readin(i))’;
switch this(1)
case ‘object’
object = this{2};
case ‘plane’
plane = str2double(this{2});
case ‘coeff’
coeff = str2double(this(2:end));
case ‘suvr’
suvr = str2double(this{2});
case ‘amax’
amax = str2double(this{2});
case ‘nfact’
nfact = str2double(this{2});
case ‘pt’
pt = str2double(this{2});
case ‘regi’
regi = str2double(this{2});
otherwise
fprintf(‘Invalid delimiter: %s! Please check your text file.n’, this{1});
return;
end
end
But a huge switch case doesn’t really give polish. I guess it shouldn’t matter if the code works, but still. I’d like it to be more refined.
Oh, yeah, the reason for all the cell array stuff (and for the huge switch case) is because I’ll be running this code (this code is a portion of a much larger script) from Linux. Also, the text file isn’t guaranteed to come in the order of object, plane, coeff, etc., which is why I have the code detect the first word.
Anyway, I thought I could solve my issue using the assignin function, but it’s not working? Here’s what I have so far.
if ismember(this(1), ["object", "plane", "coeff", "suvr", "amax", "nfact", "pt", "regi"])
if isa(this(2), ‘string’)
assignin(‘base’, this(1), this(2));
else
assignin(‘base’, this(1), str2double(this(2:end)));
end
else
fprintf(‘Invalid delimiter: %s! Please check your text file.n’, this(1));
return;
end
I’ve done my best to debug. The code is not skipping over the assignin function. That line of code is executing, but when it executes, nothing happens.
Like, I’ve checked the values of this(1) and this(2) right before the script calls the assignin function. Yes, this(1) equals "object" and this(2) equals the object name, also a string, but nothing shows up when the assignin line of code executes. I don’t get it. Would appreciate any and all suggestions. Thanks. data import, variable MATLAB Answers — New Questions
Can integral2 left a variable inside?
Hi,everyone.There’re three variables in my function,x,y and w.
I want to integral x and y first,but there were a variable w stuck in my function.Can I left it and integral x,y first? Thank you.
clear
L=0.1;
section=50;
a=L/2;
b=L/section;
v=3e8;
f1=1.2e9;
f2=4.8e9;
f3=7.5e9;
f4=10e9;
w1=(2*pi*f1);
w2=(2*pi*f2);
w3=(2*pi*f3);
w4=(2*pi*f4);
Z01=50;
Z02=75;
a0=(log(Z02/Z01))./(2.*L);
T=a;
Ub=a;
Lb=-a;
ub=a;
lb=-a;
k=6;
syms x y w
l=0:(2*L)/(2*k):L % Approximate sections dvided
sec=numel(l)-1;
% Cm0
for s=1:1:sec
for t=1:1:sec
for m=1:1:k
P1=matlabFunction(((cos((m.*pi.*(y))./a)).*(cos(2.*(x-y).*w./v))));
P2(1,m)=integral2(P1,Lb+l(s),Lb+l(s+1),Lb+l(t),@(x)x);
P3(1,m)=integral2(P1,Lb+l(s),Lb+l(s+1),@(x)x,Lb+l(t+1));
P{s,t}=(P2+P3) % s section multiply t section
end
endHi,everyone.There’re three variables in my function,x,y and w.
I want to integral x and y first,but there were a variable w stuck in my function.Can I left it and integral x,y first? Thank you.
clear
L=0.1;
section=50;
a=L/2;
b=L/section;
v=3e8;
f1=1.2e9;
f2=4.8e9;
f3=7.5e9;
f4=10e9;
w1=(2*pi*f1);
w2=(2*pi*f2);
w3=(2*pi*f3);
w4=(2*pi*f4);
Z01=50;
Z02=75;
a0=(log(Z02/Z01))./(2.*L);
T=a;
Ub=a;
Lb=-a;
ub=a;
lb=-a;
k=6;
syms x y w
l=0:(2*L)/(2*k):L % Approximate sections dvided
sec=numel(l)-1;
% Cm0
for s=1:1:sec
for t=1:1:sec
for m=1:1:k
P1=matlabFunction(((cos((m.*pi.*(y))./a)).*(cos(2.*(x-y).*w./v))));
P2(1,m)=integral2(P1,Lb+l(s),Lb+l(s+1),Lb+l(t),@(x)x);
P3(1,m)=integral2(P1,Lb+l(s),Lb+l(s+1),@(x)x,Lb+l(t+1));
P{s,t}=(P2+P3) % s section multiply t section
end
end Hi,everyone.There’re three variables in my function,x,y and w.
I want to integral x and y first,but there were a variable w stuck in my function.Can I left it and integral x,y first? Thank you.
clear
L=0.1;
section=50;
a=L/2;
b=L/section;
v=3e8;
f1=1.2e9;
f2=4.8e9;
f3=7.5e9;
f4=10e9;
w1=(2*pi*f1);
w2=(2*pi*f2);
w3=(2*pi*f3);
w4=(2*pi*f4);
Z01=50;
Z02=75;
a0=(log(Z02/Z01))./(2.*L);
T=a;
Ub=a;
Lb=-a;
ub=a;
lb=-a;
k=6;
syms x y w
l=0:(2*L)/(2*k):L % Approximate sections dvided
sec=numel(l)-1;
% Cm0
for s=1:1:sec
for t=1:1:sec
for m=1:1:k
P1=matlabFunction(((cos((m.*pi.*(y))./a)).*(cos(2.*(x-y).*w./v))));
P2(1,m)=integral2(P1,Lb+l(s),Lb+l(s+1),Lb+l(t),@(x)x);
P3(1,m)=integral2(P1,Lb+l(s),Lb+l(s+1),@(x)x,Lb+l(t+1));
P{s,t}=(P2+P3) % s section multiply t section
end
end integral2 MATLAB Answers — New Questions
I would like to find and plot the means and standard deviations for lots of columns of data.
I have gone over and over this, but I can’t seem to figure out what is going on. Eventually, I would like to plot the mean of 3 columns of data, based on their category. There are four categories, Spring, Summer, Winter, Autumn. I can import the data from excel, find the variable names, and recreate the table with just the data I want, but I can’t seem to find a way to calculate the mean based on the category. For example, I want to find the mean for all Spring for each of the final three columns. This is just one set of data. There are 8 total sets (all different lengths), so eventually, I would like to plot all of them, but I thought I would just start with 1 set. At this stage, if I can get to show the mean for table A, that would be great. Please help me get the means and standard deviations.
T = readtable(‘SdAlphabetSeasons.xlsx’);
T.Properties.VariableNames
Season = T(:,4);
dD = T(:,5);
d18O = T(:,6);
xs = T(:,7);
A = table(Season,dD,d18O,xs);
SSNMean = grpstats(A,"Season");
Function ‘subsindex’ is not defined for values of class ‘string’.
Error in dsgrpstats (line 97)
[group,glabel,groupname] = mgrp2idx(a_data(groupvars),a_nobs);
Error in grpstats (line 136)
[varargout{1:nargout}] = dsgrpstats(x,group,whichstats,varargin{:});I have gone over and over this, but I can’t seem to figure out what is going on. Eventually, I would like to plot the mean of 3 columns of data, based on their category. There are four categories, Spring, Summer, Winter, Autumn. I can import the data from excel, find the variable names, and recreate the table with just the data I want, but I can’t seem to find a way to calculate the mean based on the category. For example, I want to find the mean for all Spring for each of the final three columns. This is just one set of data. There are 8 total sets (all different lengths), so eventually, I would like to plot all of them, but I thought I would just start with 1 set. At this stage, if I can get to show the mean for table A, that would be great. Please help me get the means and standard deviations.
T = readtable(‘SdAlphabetSeasons.xlsx’);
T.Properties.VariableNames
Season = T(:,4);
dD = T(:,5);
d18O = T(:,6);
xs = T(:,7);
A = table(Season,dD,d18O,xs);
SSNMean = grpstats(A,"Season");
Function ‘subsindex’ is not defined for values of class ‘string’.
Error in dsgrpstats (line 97)
[group,glabel,groupname] = mgrp2idx(a_data(groupvars),a_nobs);
Error in grpstats (line 136)
[varargout{1:nargout}] = dsgrpstats(x,group,whichstats,varargin{:}); I have gone over and over this, but I can’t seem to figure out what is going on. Eventually, I would like to plot the mean of 3 columns of data, based on their category. There are four categories, Spring, Summer, Winter, Autumn. I can import the data from excel, find the variable names, and recreate the table with just the data I want, but I can’t seem to find a way to calculate the mean based on the category. For example, I want to find the mean for all Spring for each of the final three columns. This is just one set of data. There are 8 total sets (all different lengths), so eventually, I would like to plot all of them, but I thought I would just start with 1 set. At this stage, if I can get to show the mean for table A, that would be great. Please help me get the means and standard deviations.
T = readtable(‘SdAlphabetSeasons.xlsx’);
T.Properties.VariableNames
Season = T(:,4);
dD = T(:,5);
d18O = T(:,6);
xs = T(:,7);
A = table(Season,dD,d18O,xs);
SSNMean = grpstats(A,"Season");
Function ‘subsindex’ is not defined for values of class ‘string’.
Error in dsgrpstats (line 97)
[group,glabel,groupname] = mgrp2idx(a_data(groupvars),a_nobs);
Error in grpstats (line 136)
[varargout{1:nargout}] = dsgrpstats(x,group,whichstats,varargin{:}); table, mean, standard deviation, grpstats MATLAB Answers — New Questions
Can not know how to use minibatchqueue for a deep learning network that takes input as 4-D numbers and output 3 numbers through fully-connected layer.
There is a MATLAB example that uses minibatchqueue for input date as 4-D (image) and output as categorical. What I need is to update this example to accept output to be three numberical values (through a 3-fully connected layer).
The MATLAB example is:
[XTrain,YTrain] = digitTrain4DArrayData;
dsX = arrayDatastore(XTrain,IterationDimension=4);
dsY = arrayDatastore(YTrain);
dsTrain = combine(dsX,dsY);
classes = categories(YTrain);
numClasses = numel(classes);
net = dlnetwork;
layers = [
imageInputLayer([28 28 1],Mean=mean(XTrain,4))
convolution2dLayer(5,20)
reluLayer
convolution2dLayer(3,20,Padding=1)
reluLayer
convolution2dLayer(3,20,Padding=1)
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer];
net = addLayers(net,layers);
net = initialize(net);
miniBatchSize = 128;
mbq = minibatchqueue(dsTrain,…
MiniBatchSize=miniBatchSize,…
PartialMiniBatch="discard",…
MiniBatchFcn=@preprocessMiniBatch,…
MiniBatchFormat=["SSCB",""]);
function [X,Y] = preprocessMiniBatch(XCell,YCell)
% Extract image data from the cell array and concatenate over fourth
% dimension to add a third singleton dimension, as the channel
% dimension.
X = cat(4,XCell{:});
% Extract label data from cell and concatenate.
Y = cat(2,YCell{:});
% One-hot encode labels.
Y = onehotencode(Y,1);
end
Again, what I need is to know how to modify the code to accept three regression values at fully connected output layer.
Actually, I tried alot and alot without success. I think the main trick is the update that should be done inside this function: preprocessMiniBatch (defined above).
ThanksThere is a MATLAB example that uses minibatchqueue for input date as 4-D (image) and output as categorical. What I need is to update this example to accept output to be three numberical values (through a 3-fully connected layer).
The MATLAB example is:
[XTrain,YTrain] = digitTrain4DArrayData;
dsX = arrayDatastore(XTrain,IterationDimension=4);
dsY = arrayDatastore(YTrain);
dsTrain = combine(dsX,dsY);
classes = categories(YTrain);
numClasses = numel(classes);
net = dlnetwork;
layers = [
imageInputLayer([28 28 1],Mean=mean(XTrain,4))
convolution2dLayer(5,20)
reluLayer
convolution2dLayer(3,20,Padding=1)
reluLayer
convolution2dLayer(3,20,Padding=1)
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer];
net = addLayers(net,layers);
net = initialize(net);
miniBatchSize = 128;
mbq = minibatchqueue(dsTrain,…
MiniBatchSize=miniBatchSize,…
PartialMiniBatch="discard",…
MiniBatchFcn=@preprocessMiniBatch,…
MiniBatchFormat=["SSCB",""]);
function [X,Y] = preprocessMiniBatch(XCell,YCell)
% Extract image data from the cell array and concatenate over fourth
% dimension to add a third singleton dimension, as the channel
% dimension.
X = cat(4,XCell{:});
% Extract label data from cell and concatenate.
Y = cat(2,YCell{:});
% One-hot encode labels.
Y = onehotencode(Y,1);
end
Again, what I need is to know how to modify the code to accept three regression values at fully connected output layer.
Actually, I tried alot and alot without success. I think the main trick is the update that should be done inside this function: preprocessMiniBatch (defined above).
Thanks There is a MATLAB example that uses minibatchqueue for input date as 4-D (image) and output as categorical. What I need is to update this example to accept output to be three numberical values (through a 3-fully connected layer).
The MATLAB example is:
[XTrain,YTrain] = digitTrain4DArrayData;
dsX = arrayDatastore(XTrain,IterationDimension=4);
dsY = arrayDatastore(YTrain);
dsTrain = combine(dsX,dsY);
classes = categories(YTrain);
numClasses = numel(classes);
net = dlnetwork;
layers = [
imageInputLayer([28 28 1],Mean=mean(XTrain,4))
convolution2dLayer(5,20)
reluLayer
convolution2dLayer(3,20,Padding=1)
reluLayer
convolution2dLayer(3,20,Padding=1)
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer];
net = addLayers(net,layers);
net = initialize(net);
miniBatchSize = 128;
mbq = minibatchqueue(dsTrain,…
MiniBatchSize=miniBatchSize,…
PartialMiniBatch="discard",…
MiniBatchFcn=@preprocessMiniBatch,…
MiniBatchFormat=["SSCB",""]);
function [X,Y] = preprocessMiniBatch(XCell,YCell)
% Extract image data from the cell array and concatenate over fourth
% dimension to add a third singleton dimension, as the channel
% dimension.
X = cat(4,XCell{:});
% Extract label data from cell and concatenate.
Y = cat(2,YCell{:});
% One-hot encode labels.
Y = onehotencode(Y,1);
end
Again, what I need is to know how to modify the code to accept three regression values at fully connected output layer.
Actually, I tried alot and alot without success. I think the main trick is the update that should be done inside this function: preprocessMiniBatch (defined above).
Thanks deep learning, neural network, optimization, deep learning toolbox, deep learning toolbox model quantization library MATLAB Answers — New Questions
How to plot a poincare beam showing its singularity using polarisation distribution plot
How to have a plot as shown in figure in MATLAB. It is polarization distribution with different C points in a poincare beam. Can anyone help me pleaseHow to have a plot as shown in figure in MATLAB. It is polarization distribution with different C points in a poincare beam. Can anyone help me please How to have a plot as shown in figure in MATLAB. It is polarization distribution with different C points in a poincare beam. Can anyone help me please polarization, polarization singularity, optical vortex, vector vortex beam, poincaré beam, singularities, c points MATLAB Answers — New Questions
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN
These data are already preprocessed so they are already syncronized and they are of the same size. However, when I tried running, MATLAB says: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. What seems to be the problem with this and how can this be fixed?
% load data
clear;
clc;
ld1 = load(‘CALT23A.mat’);
ld2 = load(‘CALT23D.mat’);
ld3 = load(‘CALT23M.mat’);
ld4 = load(‘CALT23S.mat’);
ld5 = load(‘CALT23K.mat’);
%%
% Accelerometer
accx = mean([ld1.Acceleration.X ld2.Acceleration.X ld3.Acceleration.X ld4.Acceleration.X],2,’omitnan’);
accy = mean([ld1.Acceleration.Y ld2.Acceleration.Y ld3.Acceleration.Y ld4.Acceleration.Y],2,’omitnan’);
accz = mean([ld1.Acceleration.Z ld2.Acceleration.Z ld3.Acceleration.Z ld4.Acceleration.Z],2,’omitnan’);
accelerometerReadings = [accx accy accz];
% Gyroscope
angx = mean([ld1.AngularVelocity.X ld2.AngularVelocity.X ld3.AngularVelocity.X ld5.AngularVelocity.X],2,’omitnan’);
angy = mean([ld1.AngularVelocity.Y ld2.AngularVelocity.Y ld3.AngularVelocity.Y ld5.AngularVelocity.Y],2,’omitnan’);
angz = mean([ld1.AngularVelocity.Z ld2.AngularVelocity.Z ld3.AngularVelocity.Z ld5.AngularVelocity.Z],2,’omitnan’);
gyroscopeReadings = [angx angy angz];
% Magnetometer
magx = mean([ld1.MagneticField.X ld2.MagneticField.X ld3.MagneticField.X ld4.MagneticField.X],2,’omitnan’);
magy = mean([ld1.MagneticField.Y ld2.MagneticField.Y ld3.MagneticField.Y ld4.MagneticField.Y],2,’omitnan’);
magz = mean([ld1.MagneticField.Z ld2.MagneticField.Z ld3.MagneticField.Z ld4.MagneticField.Z],2,’omitnan’);
magnetometerReadings = [magx magy magz];
%GPS
lat = mean([ld1.Position.latitude ld2.Position.latitude ld3.Position.latitude ld4.Position.latitude],2,’omitnan’);
long = mean([ld1.Position.longitude ld2.Position.longitude ld3.Position.longitude ld4.Position.longitude],2,’omitnan’);
speed = mean([ld1.Position.speed ld2.Position.speed ld3.Position.speed ld4.Position.speed],2,’omitnan’);
gps_speed_combined = speed;
%% IMU Filter (indirect Kalman Filter)
fuse = imufilter(‘SampleRate’,100, ‘DecimationFactor’,1,’AccelerometerNoise’,0.5,’GyroscopeNoise’,0.01);
q1 = fuse(accelerometerReadings, gyroscopeReadings);
orient1 = eulerd(q1, ‘ZYX’,’frame’);
f = figure;
f.Position(1:4) = [100 20 1100 600];
plot(orient1(:,3)); hold off
grid on
axis tight
xlabel(‘Time (sec)’);
ylabel(‘Angle (deg)’);
title(‘Orientation Estimate using IMU Filter’)
saveas(gcf, ‘imufilter.png’)These data are already preprocessed so they are already syncronized and they are of the same size. However, when I tried running, MATLAB says: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. What seems to be the problem with this and how can this be fixed?
% load data
clear;
clc;
ld1 = load(‘CALT23A.mat’);
ld2 = load(‘CALT23D.mat’);
ld3 = load(‘CALT23M.mat’);
ld4 = load(‘CALT23S.mat’);
ld5 = load(‘CALT23K.mat’);
%%
% Accelerometer
accx = mean([ld1.Acceleration.X ld2.Acceleration.X ld3.Acceleration.X ld4.Acceleration.X],2,’omitnan’);
accy = mean([ld1.Acceleration.Y ld2.Acceleration.Y ld3.Acceleration.Y ld4.Acceleration.Y],2,’omitnan’);
accz = mean([ld1.Acceleration.Z ld2.Acceleration.Z ld3.Acceleration.Z ld4.Acceleration.Z],2,’omitnan’);
accelerometerReadings = [accx accy accz];
% Gyroscope
angx = mean([ld1.AngularVelocity.X ld2.AngularVelocity.X ld3.AngularVelocity.X ld5.AngularVelocity.X],2,’omitnan’);
angy = mean([ld1.AngularVelocity.Y ld2.AngularVelocity.Y ld3.AngularVelocity.Y ld5.AngularVelocity.Y],2,’omitnan’);
angz = mean([ld1.AngularVelocity.Z ld2.AngularVelocity.Z ld3.AngularVelocity.Z ld5.AngularVelocity.Z],2,’omitnan’);
gyroscopeReadings = [angx angy angz];
% Magnetometer
magx = mean([ld1.MagneticField.X ld2.MagneticField.X ld3.MagneticField.X ld4.MagneticField.X],2,’omitnan’);
magy = mean([ld1.MagneticField.Y ld2.MagneticField.Y ld3.MagneticField.Y ld4.MagneticField.Y],2,’omitnan’);
magz = mean([ld1.MagneticField.Z ld2.MagneticField.Z ld3.MagneticField.Z ld4.MagneticField.Z],2,’omitnan’);
magnetometerReadings = [magx magy magz];
%GPS
lat = mean([ld1.Position.latitude ld2.Position.latitude ld3.Position.latitude ld4.Position.latitude],2,’omitnan’);
long = mean([ld1.Position.longitude ld2.Position.longitude ld3.Position.longitude ld4.Position.longitude],2,’omitnan’);
speed = mean([ld1.Position.speed ld2.Position.speed ld3.Position.speed ld4.Position.speed],2,’omitnan’);
gps_speed_combined = speed;
%% IMU Filter (indirect Kalman Filter)
fuse = imufilter(‘SampleRate’,100, ‘DecimationFactor’,1,’AccelerometerNoise’,0.5,’GyroscopeNoise’,0.01);
q1 = fuse(accelerometerReadings, gyroscopeReadings);
orient1 = eulerd(q1, ‘ZYX’,’frame’);
f = figure;
f.Position(1:4) = [100 20 1100 600];
plot(orient1(:,3)); hold off
grid on
axis tight
xlabel(‘Time (sec)’);
ylabel(‘Angle (deg)’);
title(‘Orientation Estimate using IMU Filter’)
saveas(gcf, ‘imufilter.png’) These data are already preprocessed so they are already syncronized and they are of the same size. However, when I tried running, MATLAB says: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. What seems to be the problem with this and how can this be fixed?
% load data
clear;
clc;
ld1 = load(‘CALT23A.mat’);
ld2 = load(‘CALT23D.mat’);
ld3 = load(‘CALT23M.mat’);
ld4 = load(‘CALT23S.mat’);
ld5 = load(‘CALT23K.mat’);
%%
% Accelerometer
accx = mean([ld1.Acceleration.X ld2.Acceleration.X ld3.Acceleration.X ld4.Acceleration.X],2,’omitnan’);
accy = mean([ld1.Acceleration.Y ld2.Acceleration.Y ld3.Acceleration.Y ld4.Acceleration.Y],2,’omitnan’);
accz = mean([ld1.Acceleration.Z ld2.Acceleration.Z ld3.Acceleration.Z ld4.Acceleration.Z],2,’omitnan’);
accelerometerReadings = [accx accy accz];
% Gyroscope
angx = mean([ld1.AngularVelocity.X ld2.AngularVelocity.X ld3.AngularVelocity.X ld5.AngularVelocity.X],2,’omitnan’);
angy = mean([ld1.AngularVelocity.Y ld2.AngularVelocity.Y ld3.AngularVelocity.Y ld5.AngularVelocity.Y],2,’omitnan’);
angz = mean([ld1.AngularVelocity.Z ld2.AngularVelocity.Z ld3.AngularVelocity.Z ld5.AngularVelocity.Z],2,’omitnan’);
gyroscopeReadings = [angx angy angz];
% Magnetometer
magx = mean([ld1.MagneticField.X ld2.MagneticField.X ld3.MagneticField.X ld4.MagneticField.X],2,’omitnan’);
magy = mean([ld1.MagneticField.Y ld2.MagneticField.Y ld3.MagneticField.Y ld4.MagneticField.Y],2,’omitnan’);
magz = mean([ld1.MagneticField.Z ld2.MagneticField.Z ld3.MagneticField.Z ld4.MagneticField.Z],2,’omitnan’);
magnetometerReadings = [magx magy magz];
%GPS
lat = mean([ld1.Position.latitude ld2.Position.latitude ld3.Position.latitude ld4.Position.latitude],2,’omitnan’);
long = mean([ld1.Position.longitude ld2.Position.longitude ld3.Position.longitude ld4.Position.longitude],2,’omitnan’);
speed = mean([ld1.Position.speed ld2.Position.speed ld3.Position.speed ld4.Position.speed],2,’omitnan’);
gps_speed_combined = speed;
%% IMU Filter (indirect Kalman Filter)
fuse = imufilter(‘SampleRate’,100, ‘DecimationFactor’,1,’AccelerometerNoise’,0.5,’GyroscopeNoise’,0.01);
q1 = fuse(accelerometerReadings, gyroscopeReadings);
orient1 = eulerd(q1, ‘ZYX’,’frame’);
f = figure;
f.Position(1:4) = [100 20 1100 600];
plot(orient1(:,3)); hold off
grid on
axis tight
xlabel(‘Time (sec)’);
ylabel(‘Angle (deg)’);
title(‘Orientation Estimate using IMU Filter’)
saveas(gcf, ‘imufilter.png’) matrix, singular MATLAB Answers — New Questions
order using first column in array cell
newList=sortrows(newList,1);
Error using matlab.internal.math.cellstrpad
Cell elements must be character arrays.
Error in sortrows>sortBackToFrontCell (line 137)
tmp = matlab.internal.math.cellstrpad(A(I,ack));
Error in sortrows (line 77)
I = sortBackToFrontCell(A, col);newList=sortrows(newList,1);
Error using matlab.internal.math.cellstrpad
Cell elements must be character arrays.
Error in sortrows>sortBackToFrontCell (line 137)
tmp = matlab.internal.math.cellstrpad(A(I,ack));
Error in sortrows (line 77)
I = sortBackToFrontCell(A, col); newList=sortrows(newList,1);
Error using matlab.internal.math.cellstrpad
Cell elements must be character arrays.
Error in sortrows>sortBackToFrontCell (line 137)
tmp = matlab.internal.math.cellstrpad(A(I,ack));
Error in sortrows (line 77)
I = sortBackToFrontCell(A, col); order using first column in array cell MATLAB Answers — New Questions
How can I plot a spectrogram plotting time vs instantaneous frequency vs amplitude from an exported output signal?
I have a text file with time(1st column) and voltage amplitude (2nd column). How do I plot a spectrogram plotting time vs instantaneous frequency vs amplitude? Could you please help me plot it? I will really appreciate it.
I have attached the text file and a picture of the time domain representation of the signal.I have a text file with time(1st column) and voltage amplitude (2nd column). How do I plot a spectrogram plotting time vs instantaneous frequency vs amplitude? Could you please help me plot it? I will really appreciate it.
I have attached the text file and a picture of the time domain representation of the signal. I have a text file with time(1st column) and voltage amplitude (2nd column). How do I plot a spectrogram plotting time vs instantaneous frequency vs amplitude? Could you please help me plot it? I will really appreciate it.
I have attached the text file and a picture of the time domain representation of the signal. spectrogram, fft MATLAB Answers — New Questions
TS_PROCESS_CRASHED error virtualised macOS 14.4.1
Hello, I am trying to install MATLAB on a virtualised macOS 14.4.1 instance. However, the installer crashes, reporting ‘TS_PROCESS_CRASHED’. I have Corretto 11 installed and 12GB of RAM is allocated to the VM. What might be the cause of this? The host machine is a M3 Pro 36GB model.Hello, I am trying to install MATLAB on a virtualised macOS 14.4.1 instance. However, the installer crashes, reporting ‘TS_PROCESS_CRASHED’. I have Corretto 11 installed and 12GB of RAM is allocated to the VM. What might be the cause of this? The host machine is a M3 Pro 36GB model. Hello, I am trying to install MATLAB on a virtualised macOS 14.4.1 instance. However, the installer crashes, reporting ‘TS_PROCESS_CRASHED’. I have Corretto 11 installed and 12GB of RAM is allocated to the VM. What might be the cause of this? The host machine is a M3 Pro 36GB model. installation MATLAB Answers — New Questions
Creating sensor network on matlab
Dear Sir/Madam,
I just wanted to know how to create sensor network on matlab with different layers like physical,data link layer and network layer.Dear Sir/Madam,
I just wanted to know how to create sensor network on matlab with different layers like physical,data link layer and network layer. Dear Sir/Madam,
I just wanted to know how to create sensor network on matlab with different layers like physical,data link layer and network layer. sensor network MATLAB Answers — New Questions
The image errors when fitting MR damper data using bouc wen model
I’m trying to fit the MRD data using the Bouc Wen model, but there seems to be a problem with the image . I can’t find the cause of the problem.
the image just like thatI’m trying to fit the MRD data using the Bouc Wen model, but there seems to be a problem with the image . I can’t find the cause of the problem.
the image just like that I’m trying to fit the MRD data using the Bouc Wen model, but there seems to be a problem with the image . I can’t find the cause of the problem.
the image just like that bouc wen, mrdamper, matlab, curve fitting MATLAB Answers — New Questions
How to replace a dataset with different dimensions in an .H5 file – hdf5lib2 error
I have a dataset comprising a cube of images, with dimension 256x320x151. I need tu cut it down to a dataset with dimension 256x320x10, while keeping all the other attributes invariate, as they have useful information on the data acquisition parameters.
I have tried the code:
h5disp(‘PCA_cube – Copia.h5’)
fileattrib(‘PCA_cube – Copia.h5′,’+w’);
fid = H5F.open(‘PCA_cube – Copia.h5′,’H5F_ACC_RDWR’,’H5P_DEFAULT’);
dset_id = H5D.open(fid,’/Cube/Images’);
H5D.set_extent(dset_id,[320,256,10]); % C-style indexing
H5D.close(dset_id);
H5F.close(fid);
h5read(PCA_cube – Copia.h5′, ‘/Cube/Images’)
However I get the error message: "Error using hdf5lib2 : The HDF5 library encountered an error and produced the following stack trace information:H5D__set_extent dataset has contiguous storage"
I’m adding also some information on the file structure:
Any help or suggestion is much welcome!I have a dataset comprising a cube of images, with dimension 256x320x151. I need tu cut it down to a dataset with dimension 256x320x10, while keeping all the other attributes invariate, as they have useful information on the data acquisition parameters.
I have tried the code:
h5disp(‘PCA_cube – Copia.h5’)
fileattrib(‘PCA_cube – Copia.h5′,’+w’);
fid = H5F.open(‘PCA_cube – Copia.h5′,’H5F_ACC_RDWR’,’H5P_DEFAULT’);
dset_id = H5D.open(fid,’/Cube/Images’);
H5D.set_extent(dset_id,[320,256,10]); % C-style indexing
H5D.close(dset_id);
H5F.close(fid);
h5read(PCA_cube – Copia.h5′, ‘/Cube/Images’)
However I get the error message: "Error using hdf5lib2 : The HDF5 library encountered an error and produced the following stack trace information:H5D__set_extent dataset has contiguous storage"
I’m adding also some information on the file structure:
Any help or suggestion is much welcome! I have a dataset comprising a cube of images, with dimension 256x320x151. I need tu cut it down to a dataset with dimension 256x320x10, while keeping all the other attributes invariate, as they have useful information on the data acquisition parameters.
I have tried the code:
h5disp(‘PCA_cube – Copia.h5’)
fileattrib(‘PCA_cube – Copia.h5′,’+w’);
fid = H5F.open(‘PCA_cube – Copia.h5′,’H5F_ACC_RDWR’,’H5P_DEFAULT’);
dset_id = H5D.open(fid,’/Cube/Images’);
H5D.set_extent(dset_id,[320,256,10]); % C-style indexing
H5D.close(dset_id);
H5F.close(fid);
h5read(PCA_cube – Copia.h5′, ‘/Cube/Images’)
However I get the error message: "Error using hdf5lib2 : The HDF5 library encountered an error and produced the following stack trace information:H5D__set_extent dataset has contiguous storage"
I’m adding also some information on the file structure:
Any help or suggestion is much welcome! h5, hdf5lib2, dataset, hdf5 MATLAB Answers — New Questions
How can I calibrate a fixed camera to obtain accurate measurements of objects at different distances, despite height variations and pixel distortion?
I have a problem with calibration for detecting objects at different distances. I have a fixed camera, but the objects are not stationary. The issue is that when I perform the calibration using a scale to detect objects with real measurements, if the height changes, I get different results due to pixel variation. My question is how can I calculate the measurements of any object at varying distances to obtain accurate real-world results?"I have a problem with calibration for detecting objects at different distances. I have a fixed camera, but the objects are not stationary. The issue is that when I perform the calibration using a scale to detect objects with real measurements, if the height changes, I get different results due to pixel variation. My question is how can I calculate the measurements of any object at varying distances to obtain accurate real-world results?" I have a problem with calibration for detecting objects at different distances. I have a fixed camera, but the objects are not stationary. The issue is that when I perform the calibration using a scale to detect objects with real measurements, if the height changes, I get different results due to pixel variation. My question is how can I calculate the measurements of any object at varying distances to obtain accurate real-world results?" calibration, image, camera MATLAB Answers — New Questions
Why is detectImportOptions not sheet agnostic with a named Range?
I can use the following line
opts = detectImportOptions(workbookFile,’Sheet’,sheetName,’Range’,Range);
containing an excel range name (see name manager) in Range and the corresponding sheet name in sheetName. The thing is, excel already allows me to set range names for the whole workbook. So, no need to specify the sheet name. I’d like my script to be agnostic to changes in sheet names or positions.
How can I do that?
If I launch without sheetName
opts = detectImportOptions(workbookFile,’Range’,Range);
Matlab doesn’t find my range, although the range name in excel is given with "Scope: Workbook".I can use the following line
opts = detectImportOptions(workbookFile,’Sheet’,sheetName,’Range’,Range);
containing an excel range name (see name manager) in Range and the corresponding sheet name in sheetName. The thing is, excel already allows me to set range names for the whole workbook. So, no need to specify the sheet name. I’d like my script to be agnostic to changes in sheet names or positions.
How can I do that?
If I launch without sheetName
opts = detectImportOptions(workbookFile,’Range’,Range);
Matlab doesn’t find my range, although the range name in excel is given with "Scope: Workbook". I can use the following line
opts = detectImportOptions(workbookFile,’Sheet’,sheetName,’Range’,Range);
containing an excel range name (see name manager) in Range and the corresponding sheet name in sheetName. The thing is, excel already allows me to set range names for the whole workbook. So, no need to specify the sheet name. I’d like my script to be agnostic to changes in sheet names or positions.
How can I do that?
If I launch without sheetName
opts = detectImportOptions(workbookFile,’Range’,Range);
Matlab doesn’t find my range, although the range name in excel is given with "Scope: Workbook". excel MATLAB Answers — New Questions
add cell to arraycell
i want to add sistema to oldList but i reveive error
newList=[{sistema} oldList];
Error using horzcat
Dimensions of arrays being concatenated are not consistent.i want to add sistema to oldList but i reveive error
newList=[{sistema} oldList];
Error using horzcat
Dimensions of arrays being concatenated are not consistent. i want to add sistema to oldList but i reveive error
newList=[{sistema} oldList];
Error using horzcat
Dimensions of arrays being concatenated are not consistent. add cell to arraycell MATLAB Answers — New Questions
filling Index issues imfindcircles
Im having issue where i think the index is looking for instances of detected circles but it either is not filling the index or maybe there isnt enough to fill the array but im having issue getting this to work. its from the help documentation so i expected it to just work but im still having trouble and thus am having trouble understanding how to use imfindcircles. I tried using edge(canny) and using a binary image to see if that would make it easier to find circles but im still hvaing issues.
A = imread(‘coins.png’);
imshow(A)
[centers, radii, metric] = imfindcircles(A,[15 30]);
centersStrong5 = centers(1:5,:);
radiiStrong5 = radii(1:5);
metricStrong5 = metric(1:5);
viscircles(centersStrong5, radiiStrong5,’EdgeColor’,’b’);Im having issue where i think the index is looking for instances of detected circles but it either is not filling the index or maybe there isnt enough to fill the array but im having issue getting this to work. its from the help documentation so i expected it to just work but im still having trouble and thus am having trouble understanding how to use imfindcircles. I tried using edge(canny) and using a binary image to see if that would make it easier to find circles but im still hvaing issues.
A = imread(‘coins.png’);
imshow(A)
[centers, radii, metric] = imfindcircles(A,[15 30]);
centersStrong5 = centers(1:5,:);
radiiStrong5 = radii(1:5);
metricStrong5 = metric(1:5);
viscircles(centersStrong5, radiiStrong5,’EdgeColor’,’b’); Im having issue where i think the index is looking for instances of detected circles but it either is not filling the index or maybe there isnt enough to fill the array but im having issue getting this to work. its from the help documentation so i expected it to just work but im still having trouble and thus am having trouble understanding how to use imfindcircles. I tried using edge(canny) and using a binary image to see if that would make it easier to find circles but im still hvaing issues.
A = imread(‘coins.png’);
imshow(A)
[centers, radii, metric] = imfindcircles(A,[15 30]);
centersStrong5 = centers(1:5,:);
radiiStrong5 = radii(1:5);
metricStrong5 = metric(1:5);
viscircles(centersStrong5, radiiStrong5,’EdgeColor’,’b’); imfindcircles, matlab, hough transform, edge detection, image processing toolbox MATLAB Answers — New Questions
How to maximize achievable Rate for spectrum sharing in MIMO?
Hello, I am simulating a paper. I want to maximize achievable rate but there is an error in my code. the problem is maximiz (sum(log(1 + p2_k/ (sigma^2 + norm(w2_k,2)^2)))) when P2 and W2 are my variable matrices subject to 0=< p2_k =< tilde_P2 and sum( p2_k * xi_k =< zeta1_l. I used CVX function for optimization but I am not sure if it is true or not. my error is "Disciplined convex programming error:
Cannot perform the operation: {real affine} ./ {convex}" .
I would really appreciate it if someone could help me with it.
thank you in advance.Hello, I am simulating a paper. I want to maximize achievable rate but there is an error in my code. the problem is maximiz (sum(log(1 + p2_k/ (sigma^2 + norm(w2_k,2)^2)))) when P2 and W2 are my variable matrices subject to 0=< p2_k =< tilde_P2 and sum( p2_k * xi_k =< zeta1_l. I used CVX function for optimization but I am not sure if it is true or not. my error is "Disciplined convex programming error:
Cannot perform the operation: {real affine} ./ {convex}" .
I would really appreciate it if someone could help me with it.
thank you in advance. Hello, I am simulating a paper. I want to maximize achievable rate but there is an error in my code. the problem is maximiz (sum(log(1 + p2_k/ (sigma^2 + norm(w2_k,2)^2)))) when P2 and W2 are my variable matrices subject to 0=< p2_k =< tilde_P2 and sum( p2_k * xi_k =< zeta1_l. I used CVX function for optimization but I am not sure if it is true or not. my error is "Disciplined convex programming error:
Cannot perform the operation: {real affine} ./ {convex}" .
I would really appreciate it if someone could help me with it.
thank you in advance. achievable rate, spectrum sharing, matlab, for loop MATLAB Answers — New Questions
Error with addpoints when trying to animate a trajectory following a marker
I am trying to animate a trajectory following a marker.
Here is the problematic part of my code:
figure(1)
axis([0, ceil(max(x)), 0, ceil(max(y))])
daspect([1 1 1])
grid on
xlabel(‘x (m)’), ylabel(‘y (m)’), title(‘Bouncing Projectile’), subtitle([‘{theta} = ‘, num2str(theta), ‘°, u = ‘, num2str(u), ‘ ms^{-1}, h = ‘, num2str(h), ‘ m, g = ‘, num2str(g), ‘ ms^{-2}, C = ‘, num2str(C), ‘, N = ‘, num2str(N)])
h = animatedline(‘Color’, ‘b’);
p = plot(x(1), y(1), ‘o’, ‘MarkerEdgeColor’, ‘red’, ‘MarkerFaceColor’, ‘red’);
for k = 1:length(x)
p.XData = x(k);
p.YData = y(k);
addpoints(h, x(k), y(k));
drawnow limitrate
pause(dt)
end
Whithout the code for the marker, the program runs well. However, for some strange reason, adding the code for the marker seems to create an error:
Error using matlab.graphics.animation.AnimatedLine/addpoints
Value must be a handle.
Error in file (line 54)
addpoints(h, x(k), y(k));
A graph is produced when I run the program, however the axes are not labeled, there is no title, and only one point is plotted.
What mistake have I made?I am trying to animate a trajectory following a marker.
Here is the problematic part of my code:
figure(1)
axis([0, ceil(max(x)), 0, ceil(max(y))])
daspect([1 1 1])
grid on
xlabel(‘x (m)’), ylabel(‘y (m)’), title(‘Bouncing Projectile’), subtitle([‘{theta} = ‘, num2str(theta), ‘°, u = ‘, num2str(u), ‘ ms^{-1}, h = ‘, num2str(h), ‘ m, g = ‘, num2str(g), ‘ ms^{-2}, C = ‘, num2str(C), ‘, N = ‘, num2str(N)])
h = animatedline(‘Color’, ‘b’);
p = plot(x(1), y(1), ‘o’, ‘MarkerEdgeColor’, ‘red’, ‘MarkerFaceColor’, ‘red’);
for k = 1:length(x)
p.XData = x(k);
p.YData = y(k);
addpoints(h, x(k), y(k));
drawnow limitrate
pause(dt)
end
Whithout the code for the marker, the program runs well. However, for some strange reason, adding the code for the marker seems to create an error:
Error using matlab.graphics.animation.AnimatedLine/addpoints
Value must be a handle.
Error in file (line 54)
addpoints(h, x(k), y(k));
A graph is produced when I run the program, however the axes are not labeled, there is no title, and only one point is plotted.
What mistake have I made? I am trying to animate a trajectory following a marker.
Here is the problematic part of my code:
figure(1)
axis([0, ceil(max(x)), 0, ceil(max(y))])
daspect([1 1 1])
grid on
xlabel(‘x (m)’), ylabel(‘y (m)’), title(‘Bouncing Projectile’), subtitle([‘{theta} = ‘, num2str(theta), ‘°, u = ‘, num2str(u), ‘ ms^{-1}, h = ‘, num2str(h), ‘ m, g = ‘, num2str(g), ‘ ms^{-2}, C = ‘, num2str(C), ‘, N = ‘, num2str(N)])
h = animatedline(‘Color’, ‘b’);
p = plot(x(1), y(1), ‘o’, ‘MarkerEdgeColor’, ‘red’, ‘MarkerFaceColor’, ‘red’);
for k = 1:length(x)
p.XData = x(k);
p.YData = y(k);
addpoints(h, x(k), y(k));
drawnow limitrate
pause(dt)
end
Whithout the code for the marker, the program runs well. However, for some strange reason, adding the code for the marker seems to create an error:
Error using matlab.graphics.animation.AnimatedLine/addpoints
Value must be a handle.
Error in file (line 54)
addpoints(h, x(k), y(k));
A graph is produced when I run the program, however the axes are not labeled, there is no title, and only one point is plotted.
What mistake have I made? matlab MATLAB Answers — New Questions
what does the MATLAB function ‘helperMIMOChannelEstimate’ estimates
Does the function helperMIMOChannelEstimate estimates and returns perfect channel estimate or is it using any basic channel estimation algorithm like LS OR MMMSE to calculate it.Does the function helperMIMOChannelEstimate estimates and returns perfect channel estimate or is it using any basic channel estimation algorithm like LS OR MMMSE to calculate it. Does the function helperMIMOChannelEstimate estimates and returns perfect channel estimate or is it using any basic channel estimation algorithm like LS OR MMMSE to calculate it. helpermimochannelestimate, least squares, mmse MATLAB Answers — New Questions