Category: Matlab
Category Archives: Matlab
Image motion frequency estimation from scanned image
Hello all. I am trying to extract the frequency (or frequecies) of motion present in a scanned image. Consider: an object is excited with input motion at a set frequency. An image of this moving object is then taken by line scanning it (similar to how a photocopier would scan paper). The result is a "wavy" image of the object, with the frequency of the waves matching the frequency of the input motion. As an example, if the object were just a sheet of graphpaper being moved while it was scanned, the resulting image would be something like what is shown in the image below. If the speed of the scan is known, I am trying to determine the frequency of that wave. I appreciate any guidance!Hello all. I am trying to extract the frequency (or frequecies) of motion present in a scanned image. Consider: an object is excited with input motion at a set frequency. An image of this moving object is then taken by line scanning it (similar to how a photocopier would scan paper). The result is a "wavy" image of the object, with the frequency of the waves matching the frequency of the input motion. As an example, if the object were just a sheet of graphpaper being moved while it was scanned, the resulting image would be something like what is shown in the image below. If the speed of the scan is known, I am trying to determine the frequency of that wave. I appreciate any guidance! Hello all. I am trying to extract the frequency (or frequecies) of motion present in a scanned image. Consider: an object is excited with input motion at a set frequency. An image of this moving object is then taken by line scanning it (similar to how a photocopier would scan paper). The result is a "wavy" image of the object, with the frequency of the waves matching the frequency of the input motion. As an example, if the object were just a sheet of graphpaper being moved while it was scanned, the resulting image would be something like what is shown in the image below. If the speed of the scan is known, I am trying to determine the frequency of that wave. I appreciate any guidance! image analysis, image motion, frequency MATLAB Answers — New Questions
Writing tif file with multi channel and slices
Hello,
I would like to make a tif file with c=2, z=10, t=1. Input array is 4 dimension, [height, width, channel, slice]. Currently I am using the code below, however, output tif file becomes c=1, z=20, t=1. Can anybody help me to fix it?
function write3Dtiff_Slice(array, filename)
dims = size(array);
% Ensure the array has four dimensions
if length(dims) < 4
dims(end+1:4) = 1;
end
% Set data type specific fields
if isa(array, ‘single’)
bitsPerSample = 32;
sampleFormat = Tiff.SampleFormat.IEEEFP;
elseif isa(array, ‘uint16’)
bitsPerSample = 16;
sampleFormat = Tiff.SampleFormat.UInt;
elseif isa(array, ‘uint8’)
bitsPerSample = 8;
sampleFormat = Tiff.SampleFormat.UInt;
else
disp(‘Unsupported data type’);
return;
end
% Loop through slices
for s = 1:dims(4)
% Open TIFF file for each slice in append mode
outtiff = Tiff(filename, ‘a’);
% Loop through channels for the current slice
for c = 1:dims(3)
% Set tag structure for each channel of each slice
tagstruct.ImageLength = dims(1);
tagstruct.ImageWidth = dims(2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.SamplesPerPixel = 1;
tagstruct.BitsPerSample = bitsPerSample;
tagstruct.SampleFormat = sampleFormat;
% Set the tag for the current channel
outtiff.setTag(tagstruct);
% Write the channel data
outtiff.write(array(:,:,c,s));
% Create a new directory for the next channel unless it’s the last channel of the last slice
if c ~= dims(3) || s ~= dims(4)
outtiff.writeDirectory();
end
end
% Close the file for the current slice
outtiff.close();
end
endHello,
I would like to make a tif file with c=2, z=10, t=1. Input array is 4 dimension, [height, width, channel, slice]. Currently I am using the code below, however, output tif file becomes c=1, z=20, t=1. Can anybody help me to fix it?
function write3Dtiff_Slice(array, filename)
dims = size(array);
% Ensure the array has four dimensions
if length(dims) < 4
dims(end+1:4) = 1;
end
% Set data type specific fields
if isa(array, ‘single’)
bitsPerSample = 32;
sampleFormat = Tiff.SampleFormat.IEEEFP;
elseif isa(array, ‘uint16’)
bitsPerSample = 16;
sampleFormat = Tiff.SampleFormat.UInt;
elseif isa(array, ‘uint8’)
bitsPerSample = 8;
sampleFormat = Tiff.SampleFormat.UInt;
else
disp(‘Unsupported data type’);
return;
end
% Loop through slices
for s = 1:dims(4)
% Open TIFF file for each slice in append mode
outtiff = Tiff(filename, ‘a’);
% Loop through channels for the current slice
for c = 1:dims(3)
% Set tag structure for each channel of each slice
tagstruct.ImageLength = dims(1);
tagstruct.ImageWidth = dims(2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.SamplesPerPixel = 1;
tagstruct.BitsPerSample = bitsPerSample;
tagstruct.SampleFormat = sampleFormat;
% Set the tag for the current channel
outtiff.setTag(tagstruct);
% Write the channel data
outtiff.write(array(:,:,c,s));
% Create a new directory for the next channel unless it’s the last channel of the last slice
if c ~= dims(3) || s ~= dims(4)
outtiff.writeDirectory();
end
end
% Close the file for the current slice
outtiff.close();
end
end Hello,
I would like to make a tif file with c=2, z=10, t=1. Input array is 4 dimension, [height, width, channel, slice]. Currently I am using the code below, however, output tif file becomes c=1, z=20, t=1. Can anybody help me to fix it?
function write3Dtiff_Slice(array, filename)
dims = size(array);
% Ensure the array has four dimensions
if length(dims) < 4
dims(end+1:4) = 1;
end
% Set data type specific fields
if isa(array, ‘single’)
bitsPerSample = 32;
sampleFormat = Tiff.SampleFormat.IEEEFP;
elseif isa(array, ‘uint16’)
bitsPerSample = 16;
sampleFormat = Tiff.SampleFormat.UInt;
elseif isa(array, ‘uint8’)
bitsPerSample = 8;
sampleFormat = Tiff.SampleFormat.UInt;
else
disp(‘Unsupported data type’);
return;
end
% Loop through slices
for s = 1:dims(4)
% Open TIFF file for each slice in append mode
outtiff = Tiff(filename, ‘a’);
% Loop through channels for the current slice
for c = 1:dims(3)
% Set tag structure for each channel of each slice
tagstruct.ImageLength = dims(1);
tagstruct.ImageWidth = dims(2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.SamplesPerPixel = 1;
tagstruct.BitsPerSample = bitsPerSample;
tagstruct.SampleFormat = sampleFormat;
% Set the tag for the current channel
outtiff.setTag(tagstruct);
% Write the channel data
outtiff.write(array(:,:,c,s));
% Create a new directory for the next channel unless it’s the last channel of the last slice
if c ~= dims(3) || s ~= dims(4)
outtiff.writeDirectory();
end
end
% Close the file for the current slice
outtiff.close();
end
end tif, channel, slice MATLAB Answers — New Questions
Writing tif file with multi channel and slices
Hello,
I would like to make a tif file with c=2, z=10, t=1. Input array is 4 dimension, [height, width, channel, slice]. Currently I am using the code below, however, output tif file becomes c=1, z=20, t=1. Can anybody help me to fix it?
function write3Dtiff_Slice(array, filename)
dims = size(array);
% Ensure the array has four dimensions
if length(dims) < 4
dims(end+1:4) = 1;
end
% Set data type specific fields
if isa(array, ‘single’)
bitsPerSample = 32;
sampleFormat = Tiff.SampleFormat.IEEEFP;
elseif isa(array, ‘uint16’)
bitsPerSample = 16;
sampleFormat = Tiff.SampleFormat.UInt;
elseif isa(array, ‘uint8’)
bitsPerSample = 8;
sampleFormat = Tiff.SampleFormat.UInt;
else
disp(‘Unsupported data type’);
return;
end
% Loop through slices
for s = 1:dims(4)
% Open TIFF file for each slice in append mode
outtiff = Tiff(filename, ‘a’);
% Loop through channels for the current slice
for c = 1:dims(3)
% Set tag structure for each channel of each slice
tagstruct.ImageLength = dims(1);
tagstruct.ImageWidth = dims(2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.SamplesPerPixel = 1;
tagstruct.BitsPerSample = bitsPerSample;
tagstruct.SampleFormat = sampleFormat;
% Set the tag for the current channel
outtiff.setTag(tagstruct);
% Write the channel data
outtiff.write(array(:,:,c,s));
% Create a new directory for the next channel unless it’s the last channel of the last slice
if c ~= dims(3) || s ~= dims(4)
outtiff.writeDirectory();
end
end
% Close the file for the current slice
outtiff.close();
end
endHello,
I would like to make a tif file with c=2, z=10, t=1. Input array is 4 dimension, [height, width, channel, slice]. Currently I am using the code below, however, output tif file becomes c=1, z=20, t=1. Can anybody help me to fix it?
function write3Dtiff_Slice(array, filename)
dims = size(array);
% Ensure the array has four dimensions
if length(dims) < 4
dims(end+1:4) = 1;
end
% Set data type specific fields
if isa(array, ‘single’)
bitsPerSample = 32;
sampleFormat = Tiff.SampleFormat.IEEEFP;
elseif isa(array, ‘uint16’)
bitsPerSample = 16;
sampleFormat = Tiff.SampleFormat.UInt;
elseif isa(array, ‘uint8’)
bitsPerSample = 8;
sampleFormat = Tiff.SampleFormat.UInt;
else
disp(‘Unsupported data type’);
return;
end
% Loop through slices
for s = 1:dims(4)
% Open TIFF file for each slice in append mode
outtiff = Tiff(filename, ‘a’);
% Loop through channels for the current slice
for c = 1:dims(3)
% Set tag structure for each channel of each slice
tagstruct.ImageLength = dims(1);
tagstruct.ImageWidth = dims(2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.SamplesPerPixel = 1;
tagstruct.BitsPerSample = bitsPerSample;
tagstruct.SampleFormat = sampleFormat;
% Set the tag for the current channel
outtiff.setTag(tagstruct);
% Write the channel data
outtiff.write(array(:,:,c,s));
% Create a new directory for the next channel unless it’s the last channel of the last slice
if c ~= dims(3) || s ~= dims(4)
outtiff.writeDirectory();
end
end
% Close the file for the current slice
outtiff.close();
end
end Hello,
I would like to make a tif file with c=2, z=10, t=1. Input array is 4 dimension, [height, width, channel, slice]. Currently I am using the code below, however, output tif file becomes c=1, z=20, t=1. Can anybody help me to fix it?
function write3Dtiff_Slice(array, filename)
dims = size(array);
% Ensure the array has four dimensions
if length(dims) < 4
dims(end+1:4) = 1;
end
% Set data type specific fields
if isa(array, ‘single’)
bitsPerSample = 32;
sampleFormat = Tiff.SampleFormat.IEEEFP;
elseif isa(array, ‘uint16’)
bitsPerSample = 16;
sampleFormat = Tiff.SampleFormat.UInt;
elseif isa(array, ‘uint8’)
bitsPerSample = 8;
sampleFormat = Tiff.SampleFormat.UInt;
else
disp(‘Unsupported data type’);
return;
end
% Loop through slices
for s = 1:dims(4)
% Open TIFF file for each slice in append mode
outtiff = Tiff(filename, ‘a’);
% Loop through channels for the current slice
for c = 1:dims(3)
% Set tag structure for each channel of each slice
tagstruct.ImageLength = dims(1);
tagstruct.ImageWidth = dims(2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.SamplesPerPixel = 1;
tagstruct.BitsPerSample = bitsPerSample;
tagstruct.SampleFormat = sampleFormat;
% Set the tag for the current channel
outtiff.setTag(tagstruct);
% Write the channel data
outtiff.write(array(:,:,c,s));
% Create a new directory for the next channel unless it’s the last channel of the last slice
if c ~= dims(3) || s ~= dims(4)
outtiff.writeDirectory();
end
end
% Close the file for the current slice
outtiff.close();
end
end tif, channel, slice MATLAB Answers — New Questions
Is there a faster complex exponent?
Is there any way to more quickly evaluate complex exponentials, i.e:
where Q is a real array? Quick numerical tests show that complex input noticeably slows down MATLAB’s exp function.
Several thoughts:
Some libraries, such as Julia Base, provide a cis/cisoid function that directly evaluates the Euler expansion.
The GNU C library has sincos function that simultaneously evaluate sine and cosine more quickly than separate calls.
The Fixed Point Designer has a cordicexp function that seems to be identical to cis, but I don’t have this toolbox. No idea how this performs compared to the standard exp function.Is there any way to more quickly evaluate complex exponentials, i.e:
where Q is a real array? Quick numerical tests show that complex input noticeably slows down MATLAB’s exp function.
Several thoughts:
Some libraries, such as Julia Base, provide a cis/cisoid function that directly evaluates the Euler expansion.
The GNU C library has sincos function that simultaneously evaluate sine and cosine more quickly than separate calls.
The Fixed Point Designer has a cordicexp function that seems to be identical to cis, but I don’t have this toolbox. No idea how this performs compared to the standard exp function. Is there any way to more quickly evaluate complex exponentials, i.e:
where Q is a real array? Quick numerical tests show that complex input noticeably slows down MATLAB’s exp function.
Several thoughts:
Some libraries, such as Julia Base, provide a cis/cisoid function that directly evaluates the Euler expansion.
The GNU C library has sincos function that simultaneously evaluate sine and cosine more quickly than separate calls.
The Fixed Point Designer has a cordicexp function that seems to be identical to cis, but I don’t have this toolbox. No idea how this performs compared to the standard exp function. complex, exponent, cis, cisoid, sincos MATLAB Answers — New Questions
Is there a faster complex exponent?
Is there any way to more quickly evaluate complex exponentials, i.e:
where Q is a real array? Quick numerical tests show that complex input noticeably slows down MATLAB’s exp function.
Several thoughts:
Some libraries, such as Julia Base, provide a cis/cisoid function that directly evaluates the Euler expansion.
The GNU C library has sincos function that simultaneously evaluate sine and cosine more quickly than separate calls.
The Fixed Point Designer has a cordicexp function that seems to be identical to cis, but I don’t have this toolbox. No idea how this performs compared to the standard exp function.Is there any way to more quickly evaluate complex exponentials, i.e:
where Q is a real array? Quick numerical tests show that complex input noticeably slows down MATLAB’s exp function.
Several thoughts:
Some libraries, such as Julia Base, provide a cis/cisoid function that directly evaluates the Euler expansion.
The GNU C library has sincos function that simultaneously evaluate sine and cosine more quickly than separate calls.
The Fixed Point Designer has a cordicexp function that seems to be identical to cis, but I don’t have this toolbox. No idea how this performs compared to the standard exp function. Is there any way to more quickly evaluate complex exponentials, i.e:
where Q is a real array? Quick numerical tests show that complex input noticeably slows down MATLAB’s exp function.
Several thoughts:
Some libraries, such as Julia Base, provide a cis/cisoid function that directly evaluates the Euler expansion.
The GNU C library has sincos function that simultaneously evaluate sine and cosine more quickly than separate calls.
The Fixed Point Designer has a cordicexp function that seems to be identical to cis, but I don’t have this toolbox. No idea how this performs compared to the standard exp function. complex, exponent, cis, cisoid, sincos MATLAB Answers — New Questions
I need a help to plots pressure vs. Temp at equilibrium from the attached paper and in the same graph another plot using Peng Robinson model.
plot (p, T)
# in the same figure, plot using the model from the paper for P and T and compare it with Peng Robinson model. at equilibriumplot (p, T)
# in the same figure, plot using the model from the paper for P and T and compare it with Peng Robinson model. at equilibrium plot (p, T)
# in the same figure, plot using the model from the paper for P and T and compare it with Peng Robinson model. at equilibrium torsten MATLAB Answers — New Questions
Error using displayFormula First argument must be string, char, or cell array of character vectors.
I get an error while using the displayFormula() command
clc;
syms t;
K = 20;
Per = 1.5;
f1 = 100*((2734*t^5) – (6718*t^4) + (5682*t^3) – (1931*t^2) + (228*t));
f2 = -500;
aCo = (1/Per)*( int(f1, t, 0, ((2*Per)/3)) + int(f2, t, ((2*Per)/3), Per) );
w = ((2*pi)/Per);
Fo = zeros(1, K);
%% Fourier
for n=1:1:K
anCo = (1/Per)*(int(f1*cos(w*n*t),t , 0, ((2*Per)/3)) + int(f2*cos(w*n*t), t, ((2*Per)/3), Per) );
bnCo = (1/Per)*(int(f1*sin(w*n*t),t , 0, ((2*Per)/3)) + int(f2*sin(w*n*t), t, ((2*Per)/3), Per) );
Fo = Fo + ((anCo*cos(w*n*t)) + (bnCo*sin(w*n*t)));
end
Fo = Fo + aCo;
displayFormula(Fo)
figure(1)
fplot(Fo,[0 5*Per],’LineWidth’,1.5,’Color’,’#0072BD’)
xticks([0 Per 2*Per 3*Per 4*Per 5*Per])
xticklabels({‘0’, ‘1T’, ‘2T’, ‘3T’, ‘4T’, ‘5T’})
xlabel(‘Zaman (t) – [s]’)
ylabel(‘Kuvvet (F) – [N]’)
grid on
The error is:
Error using displayFormula First argument must be string, char, or cell array of character vectors.I get an error while using the displayFormula() command
clc;
syms t;
K = 20;
Per = 1.5;
f1 = 100*((2734*t^5) – (6718*t^4) + (5682*t^3) – (1931*t^2) + (228*t));
f2 = -500;
aCo = (1/Per)*( int(f1, t, 0, ((2*Per)/3)) + int(f2, t, ((2*Per)/3), Per) );
w = ((2*pi)/Per);
Fo = zeros(1, K);
%% Fourier
for n=1:1:K
anCo = (1/Per)*(int(f1*cos(w*n*t),t , 0, ((2*Per)/3)) + int(f2*cos(w*n*t), t, ((2*Per)/3), Per) );
bnCo = (1/Per)*(int(f1*sin(w*n*t),t , 0, ((2*Per)/3)) + int(f2*sin(w*n*t), t, ((2*Per)/3), Per) );
Fo = Fo + ((anCo*cos(w*n*t)) + (bnCo*sin(w*n*t)));
end
Fo = Fo + aCo;
displayFormula(Fo)
figure(1)
fplot(Fo,[0 5*Per],’LineWidth’,1.5,’Color’,’#0072BD’)
xticks([0 Per 2*Per 3*Per 4*Per 5*Per])
xticklabels({‘0’, ‘1T’, ‘2T’, ‘3T’, ‘4T’, ‘5T’})
xlabel(‘Zaman (t) – [s]’)
ylabel(‘Kuvvet (F) – [N]’)
grid on
The error is:
Error using displayFormula First argument must be string, char, or cell array of character vectors. I get an error while using the displayFormula() command
clc;
syms t;
K = 20;
Per = 1.5;
f1 = 100*((2734*t^5) – (6718*t^4) + (5682*t^3) – (1931*t^2) + (228*t));
f2 = -500;
aCo = (1/Per)*( int(f1, t, 0, ((2*Per)/3)) + int(f2, t, ((2*Per)/3), Per) );
w = ((2*pi)/Per);
Fo = zeros(1, K);
%% Fourier
for n=1:1:K
anCo = (1/Per)*(int(f1*cos(w*n*t),t , 0, ((2*Per)/3)) + int(f2*cos(w*n*t), t, ((2*Per)/3), Per) );
bnCo = (1/Per)*(int(f1*sin(w*n*t),t , 0, ((2*Per)/3)) + int(f2*sin(w*n*t), t, ((2*Per)/3), Per) );
Fo = Fo + ((anCo*cos(w*n*t)) + (bnCo*sin(w*n*t)));
end
Fo = Fo + aCo;
displayFormula(Fo)
figure(1)
fplot(Fo,[0 5*Per],’LineWidth’,1.5,’Color’,’#0072BD’)
xticks([0 Per 2*Per 3*Per 4*Per 5*Per])
xticklabels({‘0’, ‘1T’, ‘2T’, ‘3T’, ‘4T’, ‘5T’})
xlabel(‘Zaman (t) – [s]’)
ylabel(‘Kuvvet (F) – [N]’)
grid on
The error is:
Error using displayFormula First argument must be string, char, or cell array of character vectors. displayformula, mathematics, matlab, display MATLAB Answers — New Questions
How to code a discrete rotating switch from simulink into matlab
Hi, I’m new to matlab and I’m making a basic fuel system. I want to be able to control the refuel states with a discrete rotating selector switch with 5 states: refuel, refuel2desired, off, defuel2desired. Whenever I run the model I get an algabraic loop error and I don’t know why. Either it’s this section of code or I’ve done something wrong in the simulink model.
Is this code correct or is there a better way of writing it?
Thank you!
CurrentFuel = (Calculated in other section of code)
DesiredFuelQuantity = (user input)
MaxQuantity = 5180;
MinQuantity = 50;
while (RefuelSwitch == 1) && (LThrottle == 0) && (RThrottle == 0) && (EngineOnSwitch == 0)
if (RefuelState == 0)
BOpen = 0;
else
%Refuel
if (RefuelState == 1)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 1) && (CurrentFuel == MaxQuantity)
BOpen = 0;
end
%Refuel to Desired Quantity
if (RefuelState == 2)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel == DesiredFuelQuantity)
BOpen = 0;
end
%Defuel to Desired Quantity
if (RefuelState == 3)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel == DesiredFuelQuantity)
BOpen = 0;
end
%Defuel
if (RefuelState == 3)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel <= MinQuantity)
BOpen = 0;
end
end
endHi, I’m new to matlab and I’m making a basic fuel system. I want to be able to control the refuel states with a discrete rotating selector switch with 5 states: refuel, refuel2desired, off, defuel2desired. Whenever I run the model I get an algabraic loop error and I don’t know why. Either it’s this section of code or I’ve done something wrong in the simulink model.
Is this code correct or is there a better way of writing it?
Thank you!
CurrentFuel = (Calculated in other section of code)
DesiredFuelQuantity = (user input)
MaxQuantity = 5180;
MinQuantity = 50;
while (RefuelSwitch == 1) && (LThrottle == 0) && (RThrottle == 0) && (EngineOnSwitch == 0)
if (RefuelState == 0)
BOpen = 0;
else
%Refuel
if (RefuelState == 1)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 1) && (CurrentFuel == MaxQuantity)
BOpen = 0;
end
%Refuel to Desired Quantity
if (RefuelState == 2)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel == DesiredFuelQuantity)
BOpen = 0;
end
%Defuel to Desired Quantity
if (RefuelState == 3)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel == DesiredFuelQuantity)
BOpen = 0;
end
%Defuel
if (RefuelState == 3)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel <= MinQuantity)
BOpen = 0;
end
end
end Hi, I’m new to matlab and I’m making a basic fuel system. I want to be able to control the refuel states with a discrete rotating selector switch with 5 states: refuel, refuel2desired, off, defuel2desired. Whenever I run the model I get an algabraic loop error and I don’t know why. Either it’s this section of code or I’ve done something wrong in the simulink model.
Is this code correct or is there a better way of writing it?
Thank you!
CurrentFuel = (Calculated in other section of code)
DesiredFuelQuantity = (user input)
MaxQuantity = 5180;
MinQuantity = 50;
while (RefuelSwitch == 1) && (LThrottle == 0) && (RThrottle == 0) && (EngineOnSwitch == 0)
if (RefuelState == 0)
BOpen = 0;
else
%Refuel
if (RefuelState == 1)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 1) && (CurrentFuel == MaxQuantity)
BOpen = 0;
end
%Refuel to Desired Quantity
if (RefuelState == 2)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel == DesiredFuelQuantity)
BOpen = 0;
end
%Defuel to Desired Quantity
if (RefuelState == 3)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel == DesiredFuelQuantity)
BOpen = 0;
end
%Defuel
if (RefuelState == 3)
BOpen = 1;
LIOpen = 1;
RIOpen = 1;
elseif (RefuelState == 2) && (CurrentFuel <= MinQuantity)
BOpen = 0;
end
end
end matlab, simulink MATLAB Answers — New Questions
I need to find how many 0’s there are in matching places, between an array and a matrix.
I have several [1 x 8] arrays (O1-O8) and a [12 x 8] matrix (FSM), both made up of binary digits, as follows:
FSM = [0 1 0 1 1 1 0 0 0 0 0 0; 0 1 0 1 0 0 1 1 0 0 0 0; 0 1 0 1 0 0 0 0 1 1 0 0; 1 0 0 0 0 0 0 0 0 0 0 0; 1 1 1 1 0 0 0 0 0 0 0 1; 0 1 0 1 0 0 0 1 0 0 0 0; 0 1 0 1 0 0 0 0 0 1 0 0; 0 1 0 1 0 0 0 0 0 0 1 0];
O1 = [0 0 0 0 1 1 0 0 0 0 0 0];
O2 = [0 0 0 0 0 0 1 1 0 0 0 0];
O3 = [0 0 0 0 0 0 0 0 1 1 0 0];
O4 = [1 0 0 0 0 0 0 0 0 0 0 0];
O5 = [1 1 1 1 0 0 0 0 0 0 0 0];
O6 = [0 0 1 0 0 0 0 1 0 0 0 0];
O7 = [0 0 0 0 0 0 0 0 0 1 0 0];
O8 = [0 0 0 0 0 0 0 0 0 0 1 0];
I need to find, for each array, how many times there are 0’s there are in matching columns, for each row of the matrix.
For example, I would take O1, and row 1 of FSM – each of these have a 0 in the columns 1, 3, 7, 8, 9, 10, 11, 12. So they output would be 8. Then do the same for O1, for columns 2-8.
Then I can implement the code again for arrays O2-O8.I have several [1 x 8] arrays (O1-O8) and a [12 x 8] matrix (FSM), both made up of binary digits, as follows:
FSM = [0 1 0 1 1 1 0 0 0 0 0 0; 0 1 0 1 0 0 1 1 0 0 0 0; 0 1 0 1 0 0 0 0 1 1 0 0; 1 0 0 0 0 0 0 0 0 0 0 0; 1 1 1 1 0 0 0 0 0 0 0 1; 0 1 0 1 0 0 0 1 0 0 0 0; 0 1 0 1 0 0 0 0 0 1 0 0; 0 1 0 1 0 0 0 0 0 0 1 0];
O1 = [0 0 0 0 1 1 0 0 0 0 0 0];
O2 = [0 0 0 0 0 0 1 1 0 0 0 0];
O3 = [0 0 0 0 0 0 0 0 1 1 0 0];
O4 = [1 0 0 0 0 0 0 0 0 0 0 0];
O5 = [1 1 1 1 0 0 0 0 0 0 0 0];
O6 = [0 0 1 0 0 0 0 1 0 0 0 0];
O7 = [0 0 0 0 0 0 0 0 0 1 0 0];
O8 = [0 0 0 0 0 0 0 0 0 0 1 0];
I need to find, for each array, how many times there are 0’s there are in matching columns, for each row of the matrix.
For example, I would take O1, and row 1 of FSM – each of these have a 0 in the columns 1, 3, 7, 8, 9, 10, 11, 12. So they output would be 8. Then do the same for O1, for columns 2-8.
Then I can implement the code again for arrays O2-O8. I have several [1 x 8] arrays (O1-O8) and a [12 x 8] matrix (FSM), both made up of binary digits, as follows:
FSM = [0 1 0 1 1 1 0 0 0 0 0 0; 0 1 0 1 0 0 1 1 0 0 0 0; 0 1 0 1 0 0 0 0 1 1 0 0; 1 0 0 0 0 0 0 0 0 0 0 0; 1 1 1 1 0 0 0 0 0 0 0 1; 0 1 0 1 0 0 0 1 0 0 0 0; 0 1 0 1 0 0 0 0 0 1 0 0; 0 1 0 1 0 0 0 0 0 0 1 0];
O1 = [0 0 0 0 1 1 0 0 0 0 0 0];
O2 = [0 0 0 0 0 0 1 1 0 0 0 0];
O3 = [0 0 0 0 0 0 0 0 1 1 0 0];
O4 = [1 0 0 0 0 0 0 0 0 0 0 0];
O5 = [1 1 1 1 0 0 0 0 0 0 0 0];
O6 = [0 0 1 0 0 0 0 1 0 0 0 0];
O7 = [0 0 0 0 0 0 0 0 0 1 0 0];
O8 = [0 0 0 0 0 0 0 0 0 0 1 0];
I need to find, for each array, how many times there are 0’s there are in matching columns, for each row of the matrix.
For example, I would take O1, and row 1 of FSM – each of these have a 0 in the columns 1, 3, 7, 8, 9, 10, 11, 12. So they output would be 8. Then do the same for O1, for columns 2-8.
Then I can implement the code again for arrays O2-O8. matrix, matrices, matrix array MATLAB Answers — New Questions
Image motion frequency estimation from scanned image
Hello all. I am trying to extract the frequency (or frequecies) of motion present in a scanned image. Consider: an object is excited with input motion at a set frequency. An image of this moving object is then taken by line scanning it (similar to how a photocopier would scan paper). The result is a "wavy" image of the object, with the frequency of the waves matching the frequency of the input motion. As an example, if the object were just a sheet of graphpaper being moved while it was scanned, the resulting image would be something like what is shown in the image below. If the speed of the scan is known, I am trying to determine the frequency of that wave. I appreciate any guidance!Hello all. I am trying to extract the frequency (or frequecies) of motion present in a scanned image. Consider: an object is excited with input motion at a set frequency. An image of this moving object is then taken by line scanning it (similar to how a photocopier would scan paper). The result is a "wavy" image of the object, with the frequency of the waves matching the frequency of the input motion. As an example, if the object were just a sheet of graphpaper being moved while it was scanned, the resulting image would be something like what is shown in the image below. If the speed of the scan is known, I am trying to determine the frequency of that wave. I appreciate any guidance! Hello all. I am trying to extract the frequency (or frequecies) of motion present in a scanned image. Consider: an object is excited with input motion at a set frequency. An image of this moving object is then taken by line scanning it (similar to how a photocopier would scan paper). The result is a "wavy" image of the object, with the frequency of the waves matching the frequency of the input motion. As an example, if the object were just a sheet of graphpaper being moved while it was scanned, the resulting image would be something like what is shown in the image below. If the speed of the scan is known, I am trying to determine the frequency of that wave. I appreciate any guidance! image analysis, image motion, frequency MATLAB Answers — New Questions
error in edge function line 213
error description:error in line 213 [a,method,thresh,sigma,thinning,H,kx,ky] = parse_inputs(args{:});error description:error in line 213 [a,method,thresh,sigma,thinning,H,kx,ky] = parse_inputs(args{:}); error description:error in line 213 [a,method,thresh,sigma,thinning,H,kx,ky] = parse_inputs(args{:}); image processing, edge MATLAB Answers — New Questions
error in edge function line 213
error description:error in line 213 [a,method,thresh,sigma,thinning,H,kx,ky] = parse_inputs(args{:});error description:error in line 213 [a,method,thresh,sigma,thinning,H,kx,ky] = parse_inputs(args{:}); error description:error in line 213 [a,method,thresh,sigma,thinning,H,kx,ky] = parse_inputs(args{:}); image processing, edge MATLAB Answers — New Questions
how can I keep track of last n sec of data at each time step in Simulink model itself?
Hello, I am implimenting some strategy in simulink model and for this at each time step I need to look back last 3 sec data and compare it with the current time step data. I am not able to find any block which can store the last n sec data in simulink model. I have tried memory block but it only stores one time step value. The data store block stores all the time steps data. is there a way i can access only some simulation time data at each time step?Hello, I am implimenting some strategy in simulink model and for this at each time step I need to look back last 3 sec data and compare it with the current time step data. I am not able to find any block which can store the last n sec data in simulink model. I have tried memory block but it only stores one time step value. The data store block stores all the time steps data. is there a way i can access only some simulation time data at each time step? Hello, I am implimenting some strategy in simulink model and for this at each time step I need to look back last 3 sec data and compare it with the current time step data. I am not able to find any block which can store the last n sec data in simulink model. I have tried memory block but it only stores one time step value. The data store block stores all the time steps data. is there a way i can access only some simulation time data at each time step? past time step data storage MATLAB Answers — New Questions
How to interpolate 2D array from 3D array?
A=[3 4 5 6 7];
numel(X)=23;
numel(Y)=42;
There are 5 different contour data with respect to X and Y like the one belove. I have 5 different contour data of 23×42, together a 3D array of 5x23x42. There are data for the given values of A, but l need data for interpolated values of A, for example in the case of A=4.7. Then l’ll plot the data corresponding to the calculated value of A.
Thanks for your help!A=[3 4 5 6 7];
numel(X)=23;
numel(Y)=42;
There are 5 different contour data with respect to X and Y like the one belove. I have 5 different contour data of 23×42, together a 3D array of 5x23x42. There are data for the given values of A, but l need data for interpolated values of A, for example in the case of A=4.7. Then l’ll plot the data corresponding to the calculated value of A.
Thanks for your help! A=[3 4 5 6 7];
numel(X)=23;
numel(Y)=42;
There are 5 different contour data with respect to X and Y like the one belove. I have 5 different contour data of 23×42, together a 3D array of 5x23x42. There are data for the given values of A, but l need data for interpolated values of A, for example in the case of A=4.7. Then l’ll plot the data corresponding to the calculated value of A.
Thanks for your help! app designer, axes, appdesigner, matrix, array, 3d, data, contour MATLAB Answers — New Questions
Exiting: Maximum number of function evaluations has been exceeded
Hi,
I used ezyfit for gaussian functions. I got such errors.
Exiting: Maximum number of function evaluations has been exceeded
– increase MaxFunEvals option.
Current function value: 142.981920
Exiting: Maximum number of function evaluations has been exceeded
– increase MaxFunEvals option.
Current function value: 721.060509
I added "options = optimset(‘MaxFunEvals’,1000);" but the error still exists.
Please suggest. thanks a lot!
load (‘orientcurve.mat’);
OSI=zeros(size(orientcurve,1),1);
tunewidth=zeros(size(orientcurve,1),1);
tunepref=NaN(size(orientcurve,1),1);
prefdF=zeros(size(orientcurve,1),1);
options = optimset(‘MaxFunEvals’,1000);
for i=1:size(orientcurve,1)
orient=[-90 -45 0 45 90];
[~,I]=max(orientcurve(i,:));
calc_pref_or=I;
prefdF(i,3)=orientcurve(i,I);
if I==4
I=1;
else
I=I+1;
end
prefdF(i,4)=orientcurve(i,I);
if I==4
I=1;
else
I=I+1;
end
prefdF(i,5)=orientcurve(i,I);
prefdF(i,1)=orientcurve(i,I);
if I==4
I=1;
else
I=I+1;
end
prefdF(i,2)=orientcurve(i,I);
fit=ezfit(orient,prefdF(i,:),’y(x) = a*exp(-((x-x_0)^2)/(2*sigma^2)); x_0=0′);
sigma=fit.m(2);
if abs(sigma)<15
fit=ezfit(orient,prefdF(i,:),’y(x) = a*exp(-((x-x_0)^2)/(2*sigma^2)); sigma=15; x_0=0′);
sigma=fit.m(2);
end
endHi,
I used ezyfit for gaussian functions. I got such errors.
Exiting: Maximum number of function evaluations has been exceeded
– increase MaxFunEvals option.
Current function value: 142.981920
Exiting: Maximum number of function evaluations has been exceeded
– increase MaxFunEvals option.
Current function value: 721.060509
I added "options = optimset(‘MaxFunEvals’,1000);" but the error still exists.
Please suggest. thanks a lot!
load (‘orientcurve.mat’);
OSI=zeros(size(orientcurve,1),1);
tunewidth=zeros(size(orientcurve,1),1);
tunepref=NaN(size(orientcurve,1),1);
prefdF=zeros(size(orientcurve,1),1);
options = optimset(‘MaxFunEvals’,1000);
for i=1:size(orientcurve,1)
orient=[-90 -45 0 45 90];
[~,I]=max(orientcurve(i,:));
calc_pref_or=I;
prefdF(i,3)=orientcurve(i,I);
if I==4
I=1;
else
I=I+1;
end
prefdF(i,4)=orientcurve(i,I);
if I==4
I=1;
else
I=I+1;
end
prefdF(i,5)=orientcurve(i,I);
prefdF(i,1)=orientcurve(i,I);
if I==4
I=1;
else
I=I+1;
end
prefdF(i,2)=orientcurve(i,I);
fit=ezfit(orient,prefdF(i,:),’y(x) = a*exp(-((x-x_0)^2)/(2*sigma^2)); x_0=0′);
sigma=fit.m(2);
if abs(sigma)<15
fit=ezfit(orient,prefdF(i,:),’y(x) = a*exp(-((x-x_0)^2)/(2*sigma^2)); sigma=15; x_0=0′);
sigma=fit.m(2);
end
end Hi,
I used ezyfit for gaussian functions. I got such errors.
Exiting: Maximum number of function evaluations has been exceeded
– increase MaxFunEvals option.
Current function value: 142.981920
Exiting: Maximum number of function evaluations has been exceeded
– increase MaxFunEvals option.
Current function value: 721.060509
I added "options = optimset(‘MaxFunEvals’,1000);" but the error still exists.
Please suggest. thanks a lot!
load (‘orientcurve.mat’);
OSI=zeros(size(orientcurve,1),1);
tunewidth=zeros(size(orientcurve,1),1);
tunepref=NaN(size(orientcurve,1),1);
prefdF=zeros(size(orientcurve,1),1);
options = optimset(‘MaxFunEvals’,1000);
for i=1:size(orientcurve,1)
orient=[-90 -45 0 45 90];
[~,I]=max(orientcurve(i,:));
calc_pref_or=I;
prefdF(i,3)=orientcurve(i,I);
if I==4
I=1;
else
I=I+1;
end
prefdF(i,4)=orientcurve(i,I);
if I==4
I=1;
else
I=I+1;
end
prefdF(i,5)=orientcurve(i,I);
prefdF(i,1)=orientcurve(i,I);
if I==4
I=1;
else
I=I+1;
end
prefdF(i,2)=orientcurve(i,I);
fit=ezfit(orient,prefdF(i,:),’y(x) = a*exp(-((x-x_0)^2)/(2*sigma^2)); x_0=0′);
sigma=fit.m(2);
if abs(sigma)<15
fit=ezfit(orient,prefdF(i,:),’y(x) = a*exp(-((x-x_0)^2)/(2*sigma^2)); sigma=15; x_0=0′);
sigma=fit.m(2);
end
end maxfunevals MATLAB Answers — New Questions
Create 30 minute bins by reading time stamps
I have a file with time stamps, due to error in the files (gaps in time due to faulty equipment) binning 30 minute sections using the following code creates errors in the actograms produced.
function[Average] = Av_30min(y)
Average = zeros(288,size(y,2));
k = 1;
for l =1:288
Average(l,1) = mean(y(k:k+(round(length(y)/288)-1),1));
k = k+((round(length(y)/288)-1));
end
end
I want to read from say 11:30:00 – 12:00:00 and average this bin and so on and so forth. Can anyone help?
ThanksI have a file with time stamps, due to error in the files (gaps in time due to faulty equipment) binning 30 minute sections using the following code creates errors in the actograms produced.
function[Average] = Av_30min(y)
Average = zeros(288,size(y,2));
k = 1;
for l =1:288
Average(l,1) = mean(y(k:k+(round(length(y)/288)-1),1));
k = k+((round(length(y)/288)-1));
end
end
I want to read from say 11:30:00 – 12:00:00 and average this bin and so on and so forth. Can anyone help?
Thanks I have a file with time stamps, due to error in the files (gaps in time due to faulty equipment) binning 30 minute sections using the following code creates errors in the actograms produced.
function[Average] = Av_30min(y)
Average = zeros(288,size(y,2));
k = 1;
for l =1:288
Average(l,1) = mean(y(k:k+(round(length(y)/288)-1),1));
k = k+((round(length(y)/288)-1));
end
end
I want to read from say 11:30:00 – 12:00:00 and average this bin and so on and so forth. Can anyone help?
Thanks time MATLAB Answers — New Questions
Couldn’t read the exact Value from Eurotherm 3508 via Ethernet using ‘modbus TCP’ and ‘read’
Hello All, i need some help
I want to read the Temperature Value from Eurotherm 3508 Via Ethernet cable using the following instructions:
% Connecting to the Device
m = modbus(‘tcpip’,’127.0.0.1′,502,’Timeout’,10,’ByteOrder’,’big-endian’,’WordOrder’,’little-endian’)
The Connection was successfully established with the device,
% Reading the value of the temperature from the device
read(m,’holdingregs’,360,1) % The measured Temperature is written in the address 360 ‘HA027988_19_3500 User.pdf’
We also get a reading from the device but the value that we get is not the exact value of the reading, For example:
The device shows that the Temperature is : 63.2 but-MATLAB : 65379
// // // // : 22.17 but-MATLAB : 47
// // // // : -12.16 but-MATLAB : 219
// // // // : 37.09 but-MATLAB : 65505
I have tried to change the type of the data:
read(m,’holdingregs’,360,1,’uint16′),
read(m,’holdingregs’,360,1,’int16′),
read(m,’holdingregs’,360,1,’uint32′),
read(m,’holdingregs’,360,1,’int32′),
read(m,’holdingregs’,360,1,’uint64′),
read(m,’holdingregs’,360,1,’int64′),
read(m,’holdingregs’,360,1,’double’),
read(m,’holdingregs’,360,1,’single’)
but all the above doesn’t give the correct value
Do we need to convert the received value, or there is this related to the device configuration?
If any one have faced this problem before can you please help me!
Thank you very much in advenceHello All, i need some help
I want to read the Temperature Value from Eurotherm 3508 Via Ethernet cable using the following instructions:
% Connecting to the Device
m = modbus(‘tcpip’,’127.0.0.1′,502,’Timeout’,10,’ByteOrder’,’big-endian’,’WordOrder’,’little-endian’)
The Connection was successfully established with the device,
% Reading the value of the temperature from the device
read(m,’holdingregs’,360,1) % The measured Temperature is written in the address 360 ‘HA027988_19_3500 User.pdf’
We also get a reading from the device but the value that we get is not the exact value of the reading, For example:
The device shows that the Temperature is : 63.2 but-MATLAB : 65379
// // // // : 22.17 but-MATLAB : 47
// // // // : -12.16 but-MATLAB : 219
// // // // : 37.09 but-MATLAB : 65505
I have tried to change the type of the data:
read(m,’holdingregs’,360,1,’uint16′),
read(m,’holdingregs’,360,1,’int16′),
read(m,’holdingregs’,360,1,’uint32′),
read(m,’holdingregs’,360,1,’int32′),
read(m,’holdingregs’,360,1,’uint64′),
read(m,’holdingregs’,360,1,’int64′),
read(m,’holdingregs’,360,1,’double’),
read(m,’holdingregs’,360,1,’single’)
but all the above doesn’t give the correct value
Do we need to convert the received value, or there is this related to the device configuration?
If any one have faced this problem before can you please help me!
Thank you very much in advence Hello All, i need some help
I want to read the Temperature Value from Eurotherm 3508 Via Ethernet cable using the following instructions:
% Connecting to the Device
m = modbus(‘tcpip’,’127.0.0.1′,502,’Timeout’,10,’ByteOrder’,’big-endian’,’WordOrder’,’little-endian’)
The Connection was successfully established with the device,
% Reading the value of the temperature from the device
read(m,’holdingregs’,360,1) % The measured Temperature is written in the address 360 ‘HA027988_19_3500 User.pdf’
We also get a reading from the device but the value that we get is not the exact value of the reading, For example:
The device shows that the Temperature is : 63.2 but-MATLAB : 65379
// // // // : 22.17 but-MATLAB : 47
// // // // : -12.16 but-MATLAB : 219
// // // // : 37.09 but-MATLAB : 65505
I have tried to change the type of the data:
read(m,’holdingregs’,360,1,’uint16′),
read(m,’holdingregs’,360,1,’int16′),
read(m,’holdingregs’,360,1,’uint32′),
read(m,’holdingregs’,360,1,’int32′),
read(m,’holdingregs’,360,1,’uint64′),
read(m,’holdingregs’,360,1,’int64′),
read(m,’holdingregs’,360,1,’double’),
read(m,’holdingregs’,360,1,’single’)
but all the above doesn’t give the correct value
Do we need to convert the received value, or there is this related to the device configuration?
If any one have faced this problem before can you please help me!
Thank you very much in advence eurotherm 3508, data aquisition, modbus, reading from eurotherm 3508, modbus read MATLAB Answers — New Questions
why does wavelet approximation need to multiply sqrt(2)
I am learning wavelet transform, the image below is one of my examples. Notices that when down sampling the sample signal, the approximation gets multied by about sqrt(2). I know the scaling function has integral one. this property should keep the amplitude of the signal remain the same, i think. Do I need to divide sqrt(2) for each level?
This document https://www.mathworks.com/help/wavelet/ref/idwt.html, has exmple for deconstructing and reconstructing function with wavelet. But it doesn’t multiply sqrt(2).I am learning wavelet transform, the image below is one of my examples. Notices that when down sampling the sample signal, the approximation gets multied by about sqrt(2). I know the scaling function has integral one. this property should keep the amplitude of the signal remain the same, i think. Do I need to divide sqrt(2) for each level?
This document https://www.mathworks.com/help/wavelet/ref/idwt.html, has exmple for deconstructing and reconstructing function with wavelet. But it doesn’t multiply sqrt(2). I am learning wavelet transform, the image below is one of my examples. Notices that when down sampling the sample signal, the approximation gets multied by about sqrt(2). I know the scaling function has integral one. this property should keep the amplitude of the signal remain the same, i think. Do I need to divide sqrt(2) for each level?
This document https://www.mathworks.com/help/wavelet/ref/idwt.html, has exmple for deconstructing and reconstructing function with wavelet. But it doesn’t multiply sqrt(2). wavelet, signal processing MATLAB Answers — New Questions
Create 30 minute bins by reading time stamps
I have a file with time stamps, due to error in the files (gaps in time due to faulty equipment) binning 30 minute sections using the following code creates errors in the actograms produced.
function[Average] = Av_30min(y)
Average = zeros(288,size(y,2));
k = 1;
for l =1:288
Average(l,1) = mean(y(k:k+(round(length(y)/288)-1),1));
k = k+((round(length(y)/288)-1));
end
end
I want to read from say 11:30:00 – 12:00:00 and average this bin and so on and so forth. Can anyone help?
ThanksI have a file with time stamps, due to error in the files (gaps in time due to faulty equipment) binning 30 minute sections using the following code creates errors in the actograms produced.
function[Average] = Av_30min(y)
Average = zeros(288,size(y,2));
k = 1;
for l =1:288
Average(l,1) = mean(y(k:k+(round(length(y)/288)-1),1));
k = k+((round(length(y)/288)-1));
end
end
I want to read from say 11:30:00 – 12:00:00 and average this bin and so on and so forth. Can anyone help?
Thanks I have a file with time stamps, due to error in the files (gaps in time due to faulty equipment) binning 30 minute sections using the following code creates errors in the actograms produced.
function[Average] = Av_30min(y)
Average = zeros(288,size(y,2));
k = 1;
for l =1:288
Average(l,1) = mean(y(k:k+(round(length(y)/288)-1),1));
k = k+((round(length(y)/288)-1));
end
end
I want to read from say 11:30:00 – 12:00:00 and average this bin and so on and so forth. Can anyone help?
Thanks time MATLAB Answers — New Questions
trainbr returns best network by performance not the best regularized
Using trainbr in R2022b for a feedforwardnet should return the network with the best regularization. However, it seems that the best network by performance is returned. The performance in the following example is lowest in epoch 2 (as indicated by tr.best_epoch) and the returned net seem to be from this epoch (when I set net.trainParam.epochs=2 the same net results). This network is not very much regularized and the optimization process continues for another 998 epochs and ends with a "Effective # of Parameters" of roughly 4 which the result returned does not reflect at all.
If I set net.trainParam.max_fail=5; I can get train to return the net from epoch 19 which is nuch more regularized.
Long story short, I think trainbr is buggy and returns the wrong net.
rng(0)
% load data
[X, T_] = simplefit_dataset;
% resample data and apply noise
X= X(1:3:end);
T_= T_(1:3:end);
T= T_ + randn(size(T_));
% network with too many neurons
net= feedforwardnet(30, ‘trainbr’);
% net.trainParam.epochs=2;
% net.trainParam.max_fail=5;
[net, tr] = train(net, X, T);
% display results
Y = sim(net, X);
figure(1)
clf
hold on
plot(X, T_, ‘DisplayName’, ‘real’)
plot(X, Y, ‘DisplayName’, ‘model’)
plot(X(tr.trainInd), T(tr.trainInd), ‘.’, ‘DisplayName’, ‘Training’)
plot(X(tr.valInd), T(tr.valInd), ‘o’, ‘DisplayName’, ‘Validation’)
plot(X(tr.testInd), T(tr.testInd), ‘*’, ‘DisplayName’, ‘Test’)
hold off
grid on
legendUsing trainbr in R2022b for a feedforwardnet should return the network with the best regularization. However, it seems that the best network by performance is returned. The performance in the following example is lowest in epoch 2 (as indicated by tr.best_epoch) and the returned net seem to be from this epoch (when I set net.trainParam.epochs=2 the same net results). This network is not very much regularized and the optimization process continues for another 998 epochs and ends with a "Effective # of Parameters" of roughly 4 which the result returned does not reflect at all.
If I set net.trainParam.max_fail=5; I can get train to return the net from epoch 19 which is nuch more regularized.
Long story short, I think trainbr is buggy and returns the wrong net.
rng(0)
% load data
[X, T_] = simplefit_dataset;
% resample data and apply noise
X= X(1:3:end);
T_= T_(1:3:end);
T= T_ + randn(size(T_));
% network with too many neurons
net= feedforwardnet(30, ‘trainbr’);
% net.trainParam.epochs=2;
% net.trainParam.max_fail=5;
[net, tr] = train(net, X, T);
% display results
Y = sim(net, X);
figure(1)
clf
hold on
plot(X, T_, ‘DisplayName’, ‘real’)
plot(X, Y, ‘DisplayName’, ‘model’)
plot(X(tr.trainInd), T(tr.trainInd), ‘.’, ‘DisplayName’, ‘Training’)
plot(X(tr.valInd), T(tr.valInd), ‘o’, ‘DisplayName’, ‘Validation’)
plot(X(tr.testInd), T(tr.testInd), ‘*’, ‘DisplayName’, ‘Test’)
hold off
grid on
legend Using trainbr in R2022b for a feedforwardnet should return the network with the best regularization. However, it seems that the best network by performance is returned. The performance in the following example is lowest in epoch 2 (as indicated by tr.best_epoch) and the returned net seem to be from this epoch (when I set net.trainParam.epochs=2 the same net results). This network is not very much regularized and the optimization process continues for another 998 epochs and ends with a "Effective # of Parameters" of roughly 4 which the result returned does not reflect at all.
If I set net.trainParam.max_fail=5; I can get train to return the net from epoch 19 which is nuch more regularized.
Long story short, I think trainbr is buggy and returns the wrong net.
rng(0)
% load data
[X, T_] = simplefit_dataset;
% resample data and apply noise
X= X(1:3:end);
T_= T_(1:3:end);
T= T_ + randn(size(T_));
% network with too many neurons
net= feedforwardnet(30, ‘trainbr’);
% net.trainParam.epochs=2;
% net.trainParam.max_fail=5;
[net, tr] = train(net, X, T);
% display results
Y = sim(net, X);
figure(1)
clf
hold on
plot(X, T_, ‘DisplayName’, ‘real’)
plot(X, Y, ‘DisplayName’, ‘model’)
plot(X(tr.trainInd), T(tr.trainInd), ‘.’, ‘DisplayName’, ‘Training’)
plot(X(tr.valInd), T(tr.valInd), ‘o’, ‘DisplayName’, ‘Validation’)
plot(X(tr.testInd), T(tr.testInd), ‘*’, ‘DisplayName’, ‘Test’)
hold off
grid on
legend trainbr, regularization MATLAB Answers — New Questions