Tag Archives: matlab
Write a MATLAB function named areaIntegration that takes multiple input arguments representing different shapes and their coordinates. The function should integrate the areas
Write a MATLAB function named areaIntegration that takes multiple input arguments
representing different shapes and their coordinates. The function should integrate the areas made up
of these shapes using Boolean algebra and return the total integrated area.
The function signature should be:
function totalArea = areaIntegration(shape1, shape2,…)
Where shape1, shape2, etc. are arrays representing different shapes, their scale, operation, and
location. Each cell array should contain 5 elements such that:
• 1
st Element is the shape identifier where “1” represent a square and “0” present a circle.
• 2
nd Element is the scale of the shape.
• 3
rd Element is the type of operation where ‘0’ is Union, ‘1’ is Subtract, and ‘2’ is
Intersection with the shape of the previous argument.
• 4
th and 5th is the location of the shape in Cartesian coordinate (i.e. x and y).
Together they form an array like this:
[shape identifier, scale, operation type, x-coordinate, y-coordinate].
For example:
1. If the 1st argument is an array [1, 1, 2, 0, 0], it means it is a square with a 1 unit dimension
located at (0, 0), intersecting with the existing 2D space.
2. The 2nd argument, an array with the value [0, 2, 0, -1, 1], represents a circle with a 2 unit
radius located at (-1, 1) to union with the result left by the 1st argument.Write a MATLAB function named areaIntegration that takes multiple input arguments
representing different shapes and their coordinates. The function should integrate the areas made up
of these shapes using Boolean algebra and return the total integrated area.
The function signature should be:
function totalArea = areaIntegration(shape1, shape2,…)
Where shape1, shape2, etc. are arrays representing different shapes, their scale, operation, and
location. Each cell array should contain 5 elements such that:
• 1
st Element is the shape identifier where “1” represent a square and “0” present a circle.
• 2
nd Element is the scale of the shape.
• 3
rd Element is the type of operation where ‘0’ is Union, ‘1’ is Subtract, and ‘2’ is
Intersection with the shape of the previous argument.
• 4
th and 5th is the location of the shape in Cartesian coordinate (i.e. x and y).
Together they form an array like this:
[shape identifier, scale, operation type, x-coordinate, y-coordinate].
For example:
1. If the 1st argument is an array [1, 1, 2, 0, 0], it means it is a square with a 1 unit dimension
located at (0, 0), intersecting with the existing 2D space.
2. The 2nd argument, an array with the value [0, 2, 0, -1, 1], represents a circle with a 2 unit
radius located at (-1, 1) to union with the result left by the 1st argument. Write a MATLAB function named areaIntegration that takes multiple input arguments
representing different shapes and their coordinates. The function should integrate the areas made up
of these shapes using Boolean algebra and return the total integrated area.
The function signature should be:
function totalArea = areaIntegration(shape1, shape2,…)
Where shape1, shape2, etc. are arrays representing different shapes, their scale, operation, and
location. Each cell array should contain 5 elements such that:
• 1
st Element is the shape identifier where “1” represent a square and “0” present a circle.
• 2
nd Element is the scale of the shape.
• 3
rd Element is the type of operation where ‘0’ is Union, ‘1’ is Subtract, and ‘2’ is
Intersection with the shape of the previous argument.
• 4
th and 5th is the location of the shape in Cartesian coordinate (i.e. x and y).
Together they form an array like this:
[shape identifier, scale, operation type, x-coordinate, y-coordinate].
For example:
1. If the 1st argument is an array [1, 1, 2, 0, 0], it means it is a square with a 1 unit dimension
located at (0, 0), intersecting with the existing 2D space.
2. The 2nd argument, an array with the value [0, 2, 0, -1, 1], represents a circle with a 2 unit
radius located at (-1, 1) to union with the result left by the 1st argument. matlab MATLAB Answers — New Questions
can not read input from DC power to MATLAB using F28379D
Hello , I am trying to read accurate DC input by using voltege sensor & current sensor with F28379D, but unfortunately not gave me a correct input
i use matlab 2023a
if any subject wrote on it, or there are video about it or who works on it send to me (sarawi22@gmail.com) or write soluation downHello , I am trying to read accurate DC input by using voltege sensor & current sensor with F28379D, but unfortunately not gave me a correct input
i use matlab 2023a
if any subject wrote on it, or there are video about it or who works on it send to me (sarawi22@gmail.com) or write soluation down Hello , I am trying to read accurate DC input by using voltege sensor & current sensor with F28379D, but unfortunately not gave me a correct input
i use matlab 2023a
if any subject wrote on it, or there are video about it or who works on it send to me (sarawi22@gmail.com) or write soluation down dc input by f28379d MATLAB Answers — New Questions
Barchart colorbar colors from second vector
I have a variant of this question:
https://au.mathworks.com/matlabcentral/answers/506415-bar-chart-legend-and-colour?s_tid=sug_su
I have a bar chart where I am colouring the bars based on a second corresponding vector.
%%
clear
close all
clc
ids1 = [2,4,5,6,8];
meanVals = [0.2,0.204,0.199,0.208,0.19];
velMns = [16.384,16.98,17.182,18.001,18.40];
figure;
b=bar(ids1,meanVals);
xticks(ids1)
grid on
labels = pad(string(b(1).YData),6);
labelsShrt=[extractBetween(labels,1,5)]’;
xtips = b(1).XEndPoints;
ytips = b(1).YEndPoints;
text(xtips,ytips,labelsShrt,’HorizontalAlignment’,’center’,…
‘VerticalAlignment’,’bottom’,’FontSize’,8);
title(‘mean values’)
ylim([min(meanVals)-0.02 max(meanVals)+0.005])
% set bar color
MaxV = 20;
MinV = 5;
range=MaxV-MinV;
colors = jet(range); % Define a colormap
b.FaceColor = ‘flat’;
for II = 1:length(ids1)
barColorID = round(velMns(II),0)-MinV;
b.CData(II,:) = colors(barColorID,:);
end
cbar = colorbar;
caxis([MinV MaxV]);
This works as desired apart from the colormap of the colorbar, which does not correspond to the second vector.
Thanks in advanceI have a variant of this question:
https://au.mathworks.com/matlabcentral/answers/506415-bar-chart-legend-and-colour?s_tid=sug_su
I have a bar chart where I am colouring the bars based on a second corresponding vector.
%%
clear
close all
clc
ids1 = [2,4,5,6,8];
meanVals = [0.2,0.204,0.199,0.208,0.19];
velMns = [16.384,16.98,17.182,18.001,18.40];
figure;
b=bar(ids1,meanVals);
xticks(ids1)
grid on
labels = pad(string(b(1).YData),6);
labelsShrt=[extractBetween(labels,1,5)]’;
xtips = b(1).XEndPoints;
ytips = b(1).YEndPoints;
text(xtips,ytips,labelsShrt,’HorizontalAlignment’,’center’,…
‘VerticalAlignment’,’bottom’,’FontSize’,8);
title(‘mean values’)
ylim([min(meanVals)-0.02 max(meanVals)+0.005])
% set bar color
MaxV = 20;
MinV = 5;
range=MaxV-MinV;
colors = jet(range); % Define a colormap
b.FaceColor = ‘flat’;
for II = 1:length(ids1)
barColorID = round(velMns(II),0)-MinV;
b.CData(II,:) = colors(barColorID,:);
end
cbar = colorbar;
caxis([MinV MaxV]);
This works as desired apart from the colormap of the colorbar, which does not correspond to the second vector.
Thanks in advance I have a variant of this question:
https://au.mathworks.com/matlabcentral/answers/506415-bar-chart-legend-and-colour?s_tid=sug_su
I have a bar chart where I am colouring the bars based on a second corresponding vector.
%%
clear
close all
clc
ids1 = [2,4,5,6,8];
meanVals = [0.2,0.204,0.199,0.208,0.19];
velMns = [16.384,16.98,17.182,18.001,18.40];
figure;
b=bar(ids1,meanVals);
xticks(ids1)
grid on
labels = pad(string(b(1).YData),6);
labelsShrt=[extractBetween(labels,1,5)]’;
xtips = b(1).XEndPoints;
ytips = b(1).YEndPoints;
text(xtips,ytips,labelsShrt,’HorizontalAlignment’,’center’,…
‘VerticalAlignment’,’bottom’,’FontSize’,8);
title(‘mean values’)
ylim([min(meanVals)-0.02 max(meanVals)+0.005])
% set bar color
MaxV = 20;
MinV = 5;
range=MaxV-MinV;
colors = jet(range); % Define a colormap
b.FaceColor = ‘flat’;
for II = 1:length(ids1)
barColorID = round(velMns(II),0)-MinV;
b.CData(II,:) = colors(barColorID,:);
end
cbar = colorbar;
caxis([MinV MaxV]);
This works as desired apart from the colormap of the colorbar, which does not correspond to the second vector.
Thanks in advance bar, colorbar MATLAB Answers — New Questions
sol = bvp4c (OdeBVP, OdeBC, solinit, options);
ne the boundary conditions
function res = OdeBc (ya, yb, A, s, B, lambda)
global A s B lambda
res= [ya(1)-s;
ya(2)-lambda-A*ya(3);
ya(4)-1-B*ya(5);
yb(2);
yb(4)];
end
% setting the initial guess for first solution
function v = OdeInit1(x,A,s,lambda)
global A s lambda
v=[s+0.56
0
0
0
0];
end
% setting the initial guess for second solution
function v1 =OdeInit2(x, A, s)
global A s
v1 = [exp(-x)
exp(-x)
-exp(-x)
-exp(-x)
-exp(-x)];
end
endne the boundary conditions
function res = OdeBc (ya, yb, A, s, B, lambda)
global A s B lambda
res= [ya(1)-s;
ya(2)-lambda-A*ya(3);
ya(4)-1-B*ya(5);
yb(2);
yb(4)];
end
% setting the initial guess for first solution
function v = OdeInit1(x,A,s,lambda)
global A s lambda
v=[s+0.56
0
0
0
0];
end
% setting the initial guess for second solution
function v1 =OdeInit2(x, A, s)
global A s
v1 = [exp(-x)
exp(-x)
-exp(-x)
-exp(-x)
-exp(-x)];
end
end ne the boundary conditions
function res = OdeBc (ya, yb, A, s, B, lambda)
global A s B lambda
res= [ya(1)-s;
ya(2)-lambda-A*ya(3);
ya(4)-1-B*ya(5);
yb(2);
yb(4)];
end
% setting the initial guess for first solution
function v = OdeInit1(x,A,s,lambda)
global A s lambda
v=[s+0.56
0
0
0
0];
end
% setting the initial guess for second solution
function v1 =OdeInit2(x, A, s)
global A s
v1 = [exp(-x)
exp(-x)
-exp(-x)
-exp(-x)
-exp(-x)];
end
end not enough input arguments. MATLAB Answers — New Questions
CAD design in Google Earth
Can we use a CAD design in Siemens Nx as a kml file on Google earth and make animation?Can we use a CAD design in Siemens Nx as a kml file on Google earth and make animation? Can we use a CAD design in Siemens Nx as a kml file on Google earth and make animation? siemens, solidworks, matlab, matlab code, google, simulation, simulink, animation, kml, kmz, toolbox MATLAB Answers — New Questions
Why does imhist() do this?
I thought I had asked this once before, but maybe it was a fever dream. It’s hard to tell at this point.
IPT imhist() is a convenience tool for creating histograms of grayscale image data. It bins the image data such that the end bins are centered on the ends of the interval implied by the numeric class of the data (e.g. [0 1] for ‘double’). It displays the histogram using a stem() plot, with one stem in the center of each histogram bin.
This much might be disagreeable, since the end bins are effectively half-width, but let’s accept the choice to align the bin centers to the interval limits instead of aligning the bin edges.
What I can’t understand is the colorbar. Beneath the stem plot is a grayscale colorbar showing the progression N gray levels corresponding to the N histogram bins. The problem is twofold:
While the histogram bin centers are aligned to the interval limits (and cannot be changed), the gray segments of the colorbar have their edges aligned with the interval limits — and they can’t be changed either. The two are always misaligned.
The actual gray values used in the colorbar correspond to the upper edge of where the histogram bins would be if they were edge-aligned, but they’re not. The first half of the gray segments don’t even correspond to the bin they represent. The asymmetry makes plots with small N extra nonsensical.
So I put together a thing for visual emphasis and figured I’d run it here to see if it’s just my old version. It’s not.
% some inputs
inpict = rand(500);
n = 5;
% imhist can either give outputs or plot.
% it can’t do both, so we have to call it twice.
imhist(inpict,n); hold on
[counts centers] = imhist(inpict,n);
% find the axes since it won’t give them to us
hax = findobj(get(gcf,’children’),’type’,’axes’);
% figure out the bin edges from the centers,
% since it won’t give us edges either
dx = diff(centers(1:2));
xr = [centers(1)-dx/2 centers(end)+dx/2];
yr = ylim(hax(2));
% create two images:
% top is a smooth sweep from black to white.
% bottom corresponds to the center of each histogram bin.
% the two images should periodically match at each bin center.
smoothramp = repmat(linspace(xr(1),xr(2),100),[1 1 3]);
binramp = repmat(centers.’,[1 1 3]);
binramp = imresize(binramp,[1 size(smoothramp,2)],’nearest’);
% put an image behind the stem plot
hi = image(xr,yr,[binramp; smoothramp],’parent’,hax(2));
uistack(hi,’bottom’)
% find the stem plot and make it fat so it’s easier to see
hst = findobj(hax(2),’type’,’stem’);
set(hst,’linewidth’,3)
% draw a solid gray circle above each stem,
% such that the circle color is taken directly from the stem position
for k = 1:n
hp = plot(hax(2),centers(k),yr(2)*0.67,’.’);
hp.Color = [1 1 1]*centers(k);
hp.MarkerSize = 60;
end
So we have a stem plot, two images, and circular plot markers that all agree, but the color bar is off doing its own thing. The gray level in the first two colorbar segments isn’t even in the corresponding histogram bin.
Apparently this is the way imhist() has done it for at least the last 15 years, so is there actually a reason for it, or is it just one of those forever-bugs?
I’m in the middle of trying to write my way around MIMT’s usage of imhist(), and I’m inclined to just take a step back and make a complete replacement instead.I thought I had asked this once before, but maybe it was a fever dream. It’s hard to tell at this point.
IPT imhist() is a convenience tool for creating histograms of grayscale image data. It bins the image data such that the end bins are centered on the ends of the interval implied by the numeric class of the data (e.g. [0 1] for ‘double’). It displays the histogram using a stem() plot, with one stem in the center of each histogram bin.
This much might be disagreeable, since the end bins are effectively half-width, but let’s accept the choice to align the bin centers to the interval limits instead of aligning the bin edges.
What I can’t understand is the colorbar. Beneath the stem plot is a grayscale colorbar showing the progression N gray levels corresponding to the N histogram bins. The problem is twofold:
While the histogram bin centers are aligned to the interval limits (and cannot be changed), the gray segments of the colorbar have their edges aligned with the interval limits — and they can’t be changed either. The two are always misaligned.
The actual gray values used in the colorbar correspond to the upper edge of where the histogram bins would be if they were edge-aligned, but they’re not. The first half of the gray segments don’t even correspond to the bin they represent. The asymmetry makes plots with small N extra nonsensical.
So I put together a thing for visual emphasis and figured I’d run it here to see if it’s just my old version. It’s not.
% some inputs
inpict = rand(500);
n = 5;
% imhist can either give outputs or plot.
% it can’t do both, so we have to call it twice.
imhist(inpict,n); hold on
[counts centers] = imhist(inpict,n);
% find the axes since it won’t give them to us
hax = findobj(get(gcf,’children’),’type’,’axes’);
% figure out the bin edges from the centers,
% since it won’t give us edges either
dx = diff(centers(1:2));
xr = [centers(1)-dx/2 centers(end)+dx/2];
yr = ylim(hax(2));
% create two images:
% top is a smooth sweep from black to white.
% bottom corresponds to the center of each histogram bin.
% the two images should periodically match at each bin center.
smoothramp = repmat(linspace(xr(1),xr(2),100),[1 1 3]);
binramp = repmat(centers.’,[1 1 3]);
binramp = imresize(binramp,[1 size(smoothramp,2)],’nearest’);
% put an image behind the stem plot
hi = image(xr,yr,[binramp; smoothramp],’parent’,hax(2));
uistack(hi,’bottom’)
% find the stem plot and make it fat so it’s easier to see
hst = findobj(hax(2),’type’,’stem’);
set(hst,’linewidth’,3)
% draw a solid gray circle above each stem,
% such that the circle color is taken directly from the stem position
for k = 1:n
hp = plot(hax(2),centers(k),yr(2)*0.67,’.’);
hp.Color = [1 1 1]*centers(k);
hp.MarkerSize = 60;
end
So we have a stem plot, two images, and circular plot markers that all agree, but the color bar is off doing its own thing. The gray level in the first two colorbar segments isn’t even in the corresponding histogram bin.
Apparently this is the way imhist() has done it for at least the last 15 years, so is there actually a reason for it, or is it just one of those forever-bugs?
I’m in the middle of trying to write my way around MIMT’s usage of imhist(), and I’m inclined to just take a step back and make a complete replacement instead. I thought I had asked this once before, but maybe it was a fever dream. It’s hard to tell at this point.
IPT imhist() is a convenience tool for creating histograms of grayscale image data. It bins the image data such that the end bins are centered on the ends of the interval implied by the numeric class of the data (e.g. [0 1] for ‘double’). It displays the histogram using a stem() plot, with one stem in the center of each histogram bin.
This much might be disagreeable, since the end bins are effectively half-width, but let’s accept the choice to align the bin centers to the interval limits instead of aligning the bin edges.
What I can’t understand is the colorbar. Beneath the stem plot is a grayscale colorbar showing the progression N gray levels corresponding to the N histogram bins. The problem is twofold:
While the histogram bin centers are aligned to the interval limits (and cannot be changed), the gray segments of the colorbar have their edges aligned with the interval limits — and they can’t be changed either. The two are always misaligned.
The actual gray values used in the colorbar correspond to the upper edge of where the histogram bins would be if they were edge-aligned, but they’re not. The first half of the gray segments don’t even correspond to the bin they represent. The asymmetry makes plots with small N extra nonsensical.
So I put together a thing for visual emphasis and figured I’d run it here to see if it’s just my old version. It’s not.
% some inputs
inpict = rand(500);
n = 5;
% imhist can either give outputs or plot.
% it can’t do both, so we have to call it twice.
imhist(inpict,n); hold on
[counts centers] = imhist(inpict,n);
% find the axes since it won’t give them to us
hax = findobj(get(gcf,’children’),’type’,’axes’);
% figure out the bin edges from the centers,
% since it won’t give us edges either
dx = diff(centers(1:2));
xr = [centers(1)-dx/2 centers(end)+dx/2];
yr = ylim(hax(2));
% create two images:
% top is a smooth sweep from black to white.
% bottom corresponds to the center of each histogram bin.
% the two images should periodically match at each bin center.
smoothramp = repmat(linspace(xr(1),xr(2),100),[1 1 3]);
binramp = repmat(centers.’,[1 1 3]);
binramp = imresize(binramp,[1 size(smoothramp,2)],’nearest’);
% put an image behind the stem plot
hi = image(xr,yr,[binramp; smoothramp],’parent’,hax(2));
uistack(hi,’bottom’)
% find the stem plot and make it fat so it’s easier to see
hst = findobj(hax(2),’type’,’stem’);
set(hst,’linewidth’,3)
% draw a solid gray circle above each stem,
% such that the circle color is taken directly from the stem position
for k = 1:n
hp = plot(hax(2),centers(k),yr(2)*0.67,’.’);
hp.Color = [1 1 1]*centers(k);
hp.MarkerSize = 60;
end
So we have a stem plot, two images, and circular plot markers that all agree, but the color bar is off doing its own thing. The gray level in the first two colorbar segments isn’t even in the corresponding histogram bin.
Apparently this is the way imhist() has done it for at least the last 15 years, so is there actually a reason for it, or is it just one of those forever-bugs?
I’m in the middle of trying to write my way around MIMT’s usage of imhist(), and I’m inclined to just take a step back and make a complete replacement instead. imhist, histogram MATLAB Answers — New Questions
How to convert a long data file csv into a wide data file csv
Hello everyone,
I’ve this big problem with this data file csv that I would like to convert into a wide one. The aim is to obtain instead of a column in which the numerical values of Activation appear, two columns respectively Activation_1 and Activation_2. These must correspond to the relative values of the Condition, the first Cond1_N and the second Cond2_U.
Below I have attached a photo of what the original long format looks like. If anyone could help me I would be happy! Thank youHello everyone,
I’ve this big problem with this data file csv that I would like to convert into a wide one. The aim is to obtain instead of a column in which the numerical values of Activation appear, two columns respectively Activation_1 and Activation_2. These must correspond to the relative values of the Condition, the first Cond1_N and the second Cond2_U.
Below I have attached a photo of what the original long format looks like. If anyone could help me I would be happy! Thank you Hello everyone,
I’ve this big problem with this data file csv that I would like to convert into a wide one. The aim is to obtain instead of a column in which the numerical values of Activation appear, two columns respectively Activation_1 and Activation_2. These must correspond to the relative values of the Condition, the first Cond1_N and the second Cond2_U.
Below I have attached a photo of what the original long format looks like. If anyone could help me I would be happy! Thank you longtowidefile MATLAB Answers — New Questions
Need help for Influence line plotting
I am a civil engineering student specializing in Structural Design. I’m working on a project for a "Prestressed Concrete" course, where I am designing a section for a bridge with prestressed reinforcement. As part of the project, I need to first construct envelopes for the shear force and bending moment for the bridge under a loading pattern where a four-axle truck (in addition to the dead load) traverses the bridge, with different weights for the front and rear axles, thus resulting in different forces. The truck can approach the bridge from either side.
I’ve attached an image to clarify the loading pattern; ‘X’ in the image marks the truck’s position relative to the bridge’s edge.
I have developed MATLAB code that plots the shear and moment envelopes based on the influence line method. The problem is that I am getting non-symmetric graphs, which suggests there is an issue with the code.
In the attached image of the code output for the shear envelope, it can be seen that at a distance of 3 meters relative to the beam center (18 meters), the values obtained are not identical, making the graph asymmetric. I would appreciate any help to correct the code. I am open to different methods that could help solve the issue.
Thank you!!I am a civil engineering student specializing in Structural Design. I’m working on a project for a "Prestressed Concrete" course, where I am designing a section for a bridge with prestressed reinforcement. As part of the project, I need to first construct envelopes for the shear force and bending moment for the bridge under a loading pattern where a four-axle truck (in addition to the dead load) traverses the bridge, with different weights for the front and rear axles, thus resulting in different forces. The truck can approach the bridge from either side.
I’ve attached an image to clarify the loading pattern; ‘X’ in the image marks the truck’s position relative to the bridge’s edge.
I have developed MATLAB code that plots the shear and moment envelopes based on the influence line method. The problem is that I am getting non-symmetric graphs, which suggests there is an issue with the code.
In the attached image of the code output for the shear envelope, it can be seen that at a distance of 3 meters relative to the beam center (18 meters), the values obtained are not identical, making the graph asymmetric. I would appreciate any help to correct the code. I am open to different methods that could help solve the issue.
Thank you!! I am a civil engineering student specializing in Structural Design. I’m working on a project for a "Prestressed Concrete" course, where I am designing a section for a bridge with prestressed reinforcement. As part of the project, I need to first construct envelopes for the shear force and bending moment for the bridge under a loading pattern where a four-axle truck (in addition to the dead load) traverses the bridge, with different weights for the front and rear axles, thus resulting in different forces. The truck can approach the bridge from either side.
I’ve attached an image to clarify the loading pattern; ‘X’ in the image marks the truck’s position relative to the bridge’s edge.
I have developed MATLAB code that plots the shear and moment envelopes based on the influence line method. The problem is that I am getting non-symmetric graphs, which suggests there is an issue with the code.
In the attached image of the code output for the shear envelope, it can be seen that at a distance of 3 meters relative to the beam center (18 meters), the values obtained are not identical, making the graph asymmetric. I would appreciate any help to correct the code. I am open to different methods that could help solve the issue.
Thank you!! matlab function, function, civil engineering MATLAB Answers — New Questions
Improve fit quality for a custom function with near-perfect starting values
I’m trying to fit data with a relatively complicated custom function (combined logistic+linear function; combined effect of my data+noise). By trail-and-error I can manually find a good fit (indicated below), but I want MATLAB to do the final fine-tuning. Instead, the MATLAB fit is way worse than what I can do manually. As this takes minutes to do by hand and I will need to process hundreds of images, I really want to automate this.
This is the starting fit I provide manually:
<</matlabcentral/answers/uploaded_files/120202/fitInit.png>>
This is the fit after MATLAB is done (using the manual fit values as startpoint):
<</matlabcentral/answers/uploaded_files/120203/fitDone.png>>
I tried:
* Setting lower and upper bounds
* Parameter scaling (all coefficients between 1E-2 and 1E2)
* Changing algorithm
* Setting DiffMinChange and DiffMaxChange to small values
* Changing TolX and TolFun
*The main thing I don’t understand is why MATLAB worsens the fit.* Especially with low DiffMinChange and DiffMaxChange, I would expect MATLAB to give the starting fit or something better.
In case people want to try for themselves, below I provide the data and custom function.
The data-to-fit is in ‘data.txt’, while the function I use to fit it is:
I=@(Ac,b,AE,bg,bgx,x) AE.*(1./(1+1E15./Ac.*exp(-b.*x)))+bg+bgx.*x;.
The manual startpoint is
start=[1.75 0.065 14 16 0.015];
To help with interpretation of the function:
* It is a logistic function ‘1/(1+1E15./Ac*exp(-b*x))’,
* a scale-factor for the logistic function ‘AE’, (the 1E15 is to scale the parameter)
* a background offset ‘bg’, and
* a background slope ‘bgx’.I’m trying to fit data with a relatively complicated custom function (combined logistic+linear function; combined effect of my data+noise). By trail-and-error I can manually find a good fit (indicated below), but I want MATLAB to do the final fine-tuning. Instead, the MATLAB fit is way worse than what I can do manually. As this takes minutes to do by hand and I will need to process hundreds of images, I really want to automate this.
This is the starting fit I provide manually:
<</matlabcentral/answers/uploaded_files/120202/fitInit.png>>
This is the fit after MATLAB is done (using the manual fit values as startpoint):
<</matlabcentral/answers/uploaded_files/120203/fitDone.png>>
I tried:
* Setting lower and upper bounds
* Parameter scaling (all coefficients between 1E-2 and 1E2)
* Changing algorithm
* Setting DiffMinChange and DiffMaxChange to small values
* Changing TolX and TolFun
*The main thing I don’t understand is why MATLAB worsens the fit.* Especially with low DiffMinChange and DiffMaxChange, I would expect MATLAB to give the starting fit or something better.
In case people want to try for themselves, below I provide the data and custom function.
The data-to-fit is in ‘data.txt’, while the function I use to fit it is:
I=@(Ac,b,AE,bg,bgx,x) AE.*(1./(1+1E15./Ac.*exp(-b.*x)))+bg+bgx.*x;.
The manual startpoint is
start=[1.75 0.065 14 16 0.015];
To help with interpretation of the function:
* It is a logistic function ‘1/(1+1E15./Ac*exp(-b*x))’,
* a scale-factor for the logistic function ‘AE’, (the 1E15 is to scale the parameter)
* a background offset ‘bg’, and
* a background slope ‘bgx’. I’m trying to fit data with a relatively complicated custom function (combined logistic+linear function; combined effect of my data+noise). By trail-and-error I can manually find a good fit (indicated below), but I want MATLAB to do the final fine-tuning. Instead, the MATLAB fit is way worse than what I can do manually. As this takes minutes to do by hand and I will need to process hundreds of images, I really want to automate this.
This is the starting fit I provide manually:
<</matlabcentral/answers/uploaded_files/120202/fitInit.png>>
This is the fit after MATLAB is done (using the manual fit values as startpoint):
<</matlabcentral/answers/uploaded_files/120203/fitDone.png>>
I tried:
* Setting lower and upper bounds
* Parameter scaling (all coefficients between 1E-2 and 1E2)
* Changing algorithm
* Setting DiffMinChange and DiffMaxChange to small values
* Changing TolX and TolFun
*The main thing I don’t understand is why MATLAB worsens the fit.* Especially with low DiffMinChange and DiffMaxChange, I would expect MATLAB to give the starting fit or something better.
In case people want to try for themselves, below I provide the data and custom function.
The data-to-fit is in ‘data.txt’, while the function I use to fit it is:
I=@(Ac,b,AE,bg,bgx,x) AE.*(1./(1+1E15./Ac.*exp(-b.*x)))+bg+bgx.*x;.
The manual startpoint is
start=[1.75 0.065 14 16 0.015];
To help with interpretation of the function:
* It is a logistic function ‘1/(1+1E15./Ac*exp(-b*x))’,
* a scale-factor for the logistic function ‘AE’, (the 1E15 is to scale the parameter)
* a background offset ‘bg’, and
* a background slope ‘bgx’. curve fitting MATLAB Answers — New Questions
‘sparameters’ function showing error to read S-parameter data from touchstone file
I am trying to read S-parameter data from touchstone file using the following option:
sobj = sparameters(filename)
But getting the following errors
"Error using rf.file.touchstone.Data/read
Data is inconsistent with the Touchstone format.
Error in rf.file.touchstone.Data
Error in rf.internal.netparams.AllParameters/readRFFile
Error in rf.internal.netparams.AllParameters
Error in rf.internal.netparams.ScatteringParameters
Error in sparameters (line 80)
obj = obj@rf.internal.netparams.ScatteringParameters(varargin{:});"
The touchstone file is in DB/angle format
! …
# GHz S DB R 50
!
Is that an issue or the problem is somewhre else?
Note that I can read the touchstone file without any issue in other commercial software.I am trying to read S-parameter data from touchstone file using the following option:
sobj = sparameters(filename)
But getting the following errors
"Error using rf.file.touchstone.Data/read
Data is inconsistent with the Touchstone format.
Error in rf.file.touchstone.Data
Error in rf.internal.netparams.AllParameters/readRFFile
Error in rf.internal.netparams.AllParameters
Error in rf.internal.netparams.ScatteringParameters
Error in sparameters (line 80)
obj = obj@rf.internal.netparams.ScatteringParameters(varargin{:});"
The touchstone file is in DB/angle format
! …
# GHz S DB R 50
!
Is that an issue or the problem is somewhre else?
Note that I can read the touchstone file without any issue in other commercial software. I am trying to read S-parameter data from touchstone file using the following option:
sobj = sparameters(filename)
But getting the following errors
"Error using rf.file.touchstone.Data/read
Data is inconsistent with the Touchstone format.
Error in rf.file.touchstone.Data
Error in rf.internal.netparams.AllParameters/readRFFile
Error in rf.internal.netparams.AllParameters
Error in rf.internal.netparams.ScatteringParameters
Error in sparameters (line 80)
obj = obj@rf.internal.netparams.ScatteringParameters(varargin{:});"
The touchstone file is in DB/angle format
! …
# GHz S DB R 50
!
Is that an issue or the problem is somewhre else?
Note that I can read the touchstone file without any issue in other commercial software. sparameters, touchstone MATLAB Answers — New Questions
Can we sense the vibration & tilt of vehicle in driving scenario design app.
Post Content Post Content automotive, driving design scenerio, matlab, simulink MATLAB Answers — New Questions
Unable to resolve the name ‘idpack.utConvertDataToOriginalDataType’.
Hello Community
I have problems running a script with the function ‘misdata’.
The code runs fine on other computers.
Any ideas or suggetions for an alternative, or how fix the problem are highly appreciated.
%%%Code%%%
load(‘processed_data.mat’);
Ps = 7;
time = pkf(Ps).time_nan;
y = pkf(Ps).cen_nan;
u = pkf(Ps).dos_matched_nan;
%Apply a second order model for
tau = 0.5; %Time constant
us = smooth_data(time,u,tau);
%Create a timetable of the data:
TT = array2timetable([us,y],"RowTimes",minutes(time),’VariableNames’,{‘InputName’,’OutputName’});
TTm = misdata(TT); %Remove missing data
ym = TTm.OutputData;
um = TTm.InputData;
save([‘Person’,num2str(Ps),’_processed_data.mat’],"um","ym","u","us","y","time","TTm",’-mat’);
%%% Error %%%
Unable to resolve the name ‘idpack.utConvertDataToOriginalDataType’.
Error in misdata (line 166)
de = idpack.utConvertDataToOriginalDataType(de,’timetable’,’misdata’);
Error in Remove_missing_and_smooth_Data (line 16)
TTm = misdata(TT); %Remove missing dataHello Community
I have problems running a script with the function ‘misdata’.
The code runs fine on other computers.
Any ideas or suggetions for an alternative, or how fix the problem are highly appreciated.
%%%Code%%%
load(‘processed_data.mat’);
Ps = 7;
time = pkf(Ps).time_nan;
y = pkf(Ps).cen_nan;
u = pkf(Ps).dos_matched_nan;
%Apply a second order model for
tau = 0.5; %Time constant
us = smooth_data(time,u,tau);
%Create a timetable of the data:
TT = array2timetable([us,y],"RowTimes",minutes(time),’VariableNames’,{‘InputName’,’OutputName’});
TTm = misdata(TT); %Remove missing data
ym = TTm.OutputData;
um = TTm.InputData;
save([‘Person’,num2str(Ps),’_processed_data.mat’],"um","ym","u","us","y","time","TTm",’-mat’);
%%% Error %%%
Unable to resolve the name ‘idpack.utConvertDataToOriginalDataType’.
Error in misdata (line 166)
de = idpack.utConvertDataToOriginalDataType(de,’timetable’,’misdata’);
Error in Remove_missing_and_smooth_Data (line 16)
TTm = misdata(TT); %Remove missing data Hello Community
I have problems running a script with the function ‘misdata’.
The code runs fine on other computers.
Any ideas or suggetions for an alternative, or how fix the problem are highly appreciated.
%%%Code%%%
load(‘processed_data.mat’);
Ps = 7;
time = pkf(Ps).time_nan;
y = pkf(Ps).cen_nan;
u = pkf(Ps).dos_matched_nan;
%Apply a second order model for
tau = 0.5; %Time constant
us = smooth_data(time,u,tau);
%Create a timetable of the data:
TT = array2timetable([us,y],"RowTimes",minutes(time),’VariableNames’,{‘InputName’,’OutputName’});
TTm = misdata(TT); %Remove missing data
ym = TTm.OutputData;
um = TTm.InputData;
save([‘Person’,num2str(Ps),’_processed_data.mat’],"um","ym","u","us","y","time","TTm",’-mat’);
%%% Error %%%
Unable to resolve the name ‘idpack.utConvertDataToOriginalDataType’.
Error in misdata (line 166)
de = idpack.utConvertDataToOriginalDataType(de,’timetable’,’misdata’);
Error in Remove_missing_and_smooth_Data (line 16)
TTm = misdata(TT); %Remove missing data misdata MATLAB Answers — New Questions
How to check if a number is power of a prime number?
How to check if a number is power of a prime number?
e.g. 9, 25, 27, 36 are powers of a prime number. Program should return logical 1 for these kinds of numbers.How to check if a number is power of a prime number?
e.g. 9, 25, 27, 36 are powers of a prime number. Program should return logical 1 for these kinds of numbers. How to check if a number is power of a prime number?
e.g. 9, 25, 27, 36 are powers of a prime number. Program should return logical 1 for these kinds of numbers. prime-power check MATLAB Answers — New Questions
Why can’t I call a specified value in a 4D matrix mat-file when the last dimension is larger than 200?
Hi everyone,
I have one variable ‘irf’ sized 2241x5x105x10000 in a mat-file ver 7.3. When I load the mat-file and call the variable it returns all the values.
However, if I call certain specified value for ex irf(a,b,c,d) and d is larger than 200, Matlab always returns the value as 0.
I tried using m=matfile(‘myfile.mat’, ‘Writable’, false) then call m.irf(a,b,c,d) and still the value for d larger than 200 is always 0.
What did I do wrong here? How can I call a specified located value in my variable when d is larger than 200?
I work with Matlab 2024a with 128GB RAM in a virtual machine.
Many thanks in advanceHi everyone,
I have one variable ‘irf’ sized 2241x5x105x10000 in a mat-file ver 7.3. When I load the mat-file and call the variable it returns all the values.
However, if I call certain specified value for ex irf(a,b,c,d) and d is larger than 200, Matlab always returns the value as 0.
I tried using m=matfile(‘myfile.mat’, ‘Writable’, false) then call m.irf(a,b,c,d) and still the value for d larger than 200 is always 0.
What did I do wrong here? How can I call a specified located value in my variable when d is larger than 200?
I work with Matlab 2024a with 128GB RAM in a virtual machine.
Many thanks in advance Hi everyone,
I have one variable ‘irf’ sized 2241x5x105x10000 in a mat-file ver 7.3. When I load the mat-file and call the variable it returns all the values.
However, if I call certain specified value for ex irf(a,b,c,d) and d is larger than 200, Matlab always returns the value as 0.
I tried using m=matfile(‘myfile.mat’, ‘Writable’, false) then call m.irf(a,b,c,d) and still the value for d larger than 200 is always 0.
What did I do wrong here? How can I call a specified located value in my variable when d is larger than 200?
I work with Matlab 2024a with 128GB RAM in a virtual machine.
Many thanks in advance mat-file, large data MATLAB Answers — New Questions
Programmatically adjust the width of Document Bar
I am looking for a way to programatically adjust the width of this panel, does anyone have any ideas?
I am using setDocumentBarPosition to move this panel to the left side onf the window. I would like to adjust it’s width but can’t figure out how. I am able to get it’s current inset value using getGroupContainerInsets but am stuck at trying to figure out how to modify it. there is definitely something that matlab is storing in the background because it remembers the width when i re-create the group in a different instance of matlab.I am looking for a way to programatically adjust the width of this panel, does anyone have any ideas?
I am using setDocumentBarPosition to move this panel to the left side onf the window. I would like to adjust it’s width but can’t figure out how. I am able to get it’s current inset value using getGroupContainerInsets but am stuck at trying to figure out how to modify it. there is definitely something that matlab is storing in the background because it remembers the width when i re-create the group in a different instance of matlab. I am looking for a way to programatically adjust the width of this panel, does anyone have any ideas?
I am using setDocumentBarPosition to move this panel to the left side onf the window. I would like to adjust it’s width but can’t figure out how. I am able to get it’s current inset value using getGroupContainerInsets but am stuck at trying to figure out how to modify it. there is definitely something that matlab is storing in the background because it remembers the width when i re-create the group in a different instance of matlab. jframe, figure, undocumented MATLAB Answers — New Questions
program block diagram in matlab, not simulink
Hi,
I have an task to calculate the transferfunction with an given, complicated block diagram. So I simplify the block diagram until I have the complete transfer function in the last block – not a problem. Now I have the next task which tells me to proof that my previous calculations are correct using matlab (not simulink, which would be the third task; and I have already done that to make sure my transfer function from task a) was correct)
So my question is: how do I translate a block diagram with given transfer functions into matlab code? I can easily define all the blocks’ transfer functions like G1=tf(c1,d1);, but how do I tell matlab in code where a sum is, where a branch splits etc?
I would realy appreciate any help, as that is something our professor does not show in his vids and leaves to our own to figure out -.-
Thank you very much,
DennisHi,
I have an task to calculate the transferfunction with an given, complicated block diagram. So I simplify the block diagram until I have the complete transfer function in the last block – not a problem. Now I have the next task which tells me to proof that my previous calculations are correct using matlab (not simulink, which would be the third task; and I have already done that to make sure my transfer function from task a) was correct)
So my question is: how do I translate a block diagram with given transfer functions into matlab code? I can easily define all the blocks’ transfer functions like G1=tf(c1,d1);, but how do I tell matlab in code where a sum is, where a branch splits etc?
I would realy appreciate any help, as that is something our professor does not show in his vids and leaves to our own to figure out -.-
Thank you very much,
Dennis Hi,
I have an task to calculate the transferfunction with an given, complicated block diagram. So I simplify the block diagram until I have the complete transfer function in the last block – not a problem. Now I have the next task which tells me to proof that my previous calculations are correct using matlab (not simulink, which would be the third task; and I have already done that to make sure my transfer function from task a) was correct)
So my question is: how do I translate a block diagram with given transfer functions into matlab code? I can easily define all the blocks’ transfer functions like G1=tf(c1,d1);, but how do I tell matlab in code where a sum is, where a branch splits etc?
I would realy appreciate any help, as that is something our professor does not show in his vids and leaves to our own to figure out -.-
Thank you very much,
Dennis block diagram, transfer function, matlab MATLAB Answers — New Questions
Correct the code for me please
% Given data points
x = [0,0.1, 0.8, 0.6, 0.9, 1];
f = [-1,-1.2299,-3.455, -2.9949, -3.3929, -3];
% Part (a) – Construct the divided difference table
n = length(x);
d = zeros(n);
d(1,1) = f(1);
for i = 2:n
d(i,1) = (f(i) – f(i-1))/(x(i) – x(i-1));
for j = 2:i
d(i,j) = (d(i,j-1) – d(i-1,j-1))/(x(i) – x(i-j));
end
end
disp(‘Divided Difference Table:’)
disp(d)
% Part (b) – Evaluate the polynomial of order "n-1"
y = 0;
for i = 1:n
temp = f(1);
for j = 1:i
temp = temp * (0.5 – x(1:i-j)) + d(i,j);
end
y = y + temp;
end
fprintf(‘The value of the polynomial at x = 0.5 is %.4fn’, y)
% Part (c) – Evaluate f(0.5)
f_interp = interp1(x,f,0.5);
fprintf(‘The value of f(0.5) is %.4fn’, f_interp)
% Part (d) – Check your answers using built-in MATLAB functions
p = polyfit(x,f,5);
y_polyfit = polyval(p,0.5);
fprintf(‘The value of the polynomial at x = 0.5 using polyfit is %.4fn’, y_polyfit)
f_interp_polyfit = interp1(x,f,0.5,’linear’);
fprintf(‘The value of f(0.5) using interp1 is %.4fn’, f_interp_polyfit)% Given data points
x = [0,0.1, 0.8, 0.6, 0.9, 1];
f = [-1,-1.2299,-3.455, -2.9949, -3.3929, -3];
% Part (a) – Construct the divided difference table
n = length(x);
d = zeros(n);
d(1,1) = f(1);
for i = 2:n
d(i,1) = (f(i) – f(i-1))/(x(i) – x(i-1));
for j = 2:i
d(i,j) = (d(i,j-1) – d(i-1,j-1))/(x(i) – x(i-j));
end
end
disp(‘Divided Difference Table:’)
disp(d)
% Part (b) – Evaluate the polynomial of order "n-1"
y = 0;
for i = 1:n
temp = f(1);
for j = 1:i
temp = temp * (0.5 – x(1:i-j)) + d(i,j);
end
y = y + temp;
end
fprintf(‘The value of the polynomial at x = 0.5 is %.4fn’, y)
% Part (c) – Evaluate f(0.5)
f_interp = interp1(x,f,0.5);
fprintf(‘The value of f(0.5) is %.4fn’, f_interp)
% Part (d) – Check your answers using built-in MATLAB functions
p = polyfit(x,f,5);
y_polyfit = polyval(p,0.5);
fprintf(‘The value of the polynomial at x = 0.5 using polyfit is %.4fn’, y_polyfit)
f_interp_polyfit = interp1(x,f,0.5,’linear’);
fprintf(‘The value of f(0.5) using interp1 is %.4fn’, f_interp_polyfit) % Given data points
x = [0,0.1, 0.8, 0.6, 0.9, 1];
f = [-1,-1.2299,-3.455, -2.9949, -3.3929, -3];
% Part (a) – Construct the divided difference table
n = length(x);
d = zeros(n);
d(1,1) = f(1);
for i = 2:n
d(i,1) = (f(i) – f(i-1))/(x(i) – x(i-1));
for j = 2:i
d(i,j) = (d(i,j-1) – d(i-1,j-1))/(x(i) – x(i-j));
end
end
disp(‘Divided Difference Table:’)
disp(d)
% Part (b) – Evaluate the polynomial of order "n-1"
y = 0;
for i = 1:n
temp = f(1);
for j = 1:i
temp = temp * (0.5 – x(1:i-j)) + d(i,j);
end
y = y + temp;
end
fprintf(‘The value of the polynomial at x = 0.5 is %.4fn’, y)
% Part (c) – Evaluate f(0.5)
f_interp = interp1(x,f,0.5);
fprintf(‘The value of f(0.5) is %.4fn’, f_interp)
% Part (d) – Check your answers using built-in MATLAB functions
p = polyfit(x,f,5);
y_polyfit = polyval(p,0.5);
fprintf(‘The value of the polynomial at x = 0.5 using polyfit is %.4fn’, y_polyfit)
f_interp_polyfit = interp1(x,f,0.5,’linear’);
fprintf(‘The value of f(0.5) using interp1 is %.4fn’, f_interp_polyfit) numerical MATLAB Answers — New Questions
My User-defined Function is in red
I followed the exact format to set up a user-defined function in the first line. Even my classmates’ worked perfectly fine but mine. Can anyone show me why my function is in red?I followed the exact format to set up a user-defined function in the first line. Even my classmates’ worked perfectly fine but mine. Can anyone show me why my function is in red? I followed the exact format to set up a user-defined function in the first line. Even my classmates’ worked perfectly fine but mine. Can anyone show me why my function is in red? user-defined functions MATLAB Answers — New Questions
What is the reason that GoogleNet takes less time than MobileNetv2 and EfficientNet-b0 for feature extraction from a set of images?
I am using 3 Pre-trained networks namely GoogLeNet, MobileNetv2 and EfficientNet-b0 for feature extraction task on a set of images. Time taken (in seconds per frame) by GoogLeNet among these three networks is the least, whereas EfficientNet-b0 took the longest time. MobileNetv2 fell in between these two. In summary, we can show time taken (in seconds per frame) by these networks as following:
GoogLeNet < MobileNetv2 < EfficientNet-b0
I am trying to find a valid reason for this. Can this be attributed to the fact that depth of GoogLeNet is 22, being less than the depth of MobileNetv2 ( 53) and depth of EfficientNet-b0 being 82 ?
Can someone please put some light on this?
I have also gone through the plot shown in the following link that shows that realtive prediction time of GoogLeNet is less than MobileNetv2 which is less than EfficientNet-b0
https://in.mathworks.com/help/deeplearning/ug/pretrained-convolutional-neural-networks.htmlI am using 3 Pre-trained networks namely GoogLeNet, MobileNetv2 and EfficientNet-b0 for feature extraction task on a set of images. Time taken (in seconds per frame) by GoogLeNet among these three networks is the least, whereas EfficientNet-b0 took the longest time. MobileNetv2 fell in between these two. In summary, we can show time taken (in seconds per frame) by these networks as following:
GoogLeNet < MobileNetv2 < EfficientNet-b0
I am trying to find a valid reason for this. Can this be attributed to the fact that depth of GoogLeNet is 22, being less than the depth of MobileNetv2 ( 53) and depth of EfficientNet-b0 being 82 ?
Can someone please put some light on this?
I have also gone through the plot shown in the following link that shows that realtive prediction time of GoogLeNet is less than MobileNetv2 which is less than EfficientNet-b0
https://in.mathworks.com/help/deeplearning/ug/pretrained-convolutional-neural-networks.html I am using 3 Pre-trained networks namely GoogLeNet, MobileNetv2 and EfficientNet-b0 for feature extraction task on a set of images. Time taken (in seconds per frame) by GoogLeNet among these three networks is the least, whereas EfficientNet-b0 took the longest time. MobileNetv2 fell in between these two. In summary, we can show time taken (in seconds per frame) by these networks as following:
GoogLeNet < MobileNetv2 < EfficientNet-b0
I am trying to find a valid reason for this. Can this be attributed to the fact that depth of GoogLeNet is 22, being less than the depth of MobileNetv2 ( 53) and depth of EfficientNet-b0 being 82 ?
Can someone please put some light on this?
I have also gone through the plot shown in the following link that shows that realtive prediction time of GoogLeNet is less than MobileNetv2 which is less than EfficientNet-b0
https://in.mathworks.com/help/deeplearning/ug/pretrained-convolutional-neural-networks.html pre-trained networks, googlenet, mobilenetv2, deep learning, matlab, neural networks, efficientnet-b0 MATLAB Answers — New Questions
Time Scaling In Discrete Time Signals
Hello everyone. I want to apply time scaling property to my signal. It is hard for me to apply for the signals especially like x[4n], x[2n], x[1/3n]. I know there must be mod calculation because the values should be integer but i could not write the code can someone help me please?
n=[-2 -1 0 1 2 3 4];
x=[3 1 0 4 6 2 9];Hello everyone. I want to apply time scaling property to my signal. It is hard for me to apply for the signals especially like x[4n], x[2n], x[1/3n]. I know there must be mod calculation because the values should be integer but i could not write the code can someone help me please?
n=[-2 -1 0 1 2 3 4];
x=[3 1 0 4 6 2 9]; Hello everyone. I want to apply time scaling property to my signal. It is hard for me to apply for the signals especially like x[4n], x[2n], x[1/3n]. I know there must be mod calculation because the values should be integer but i could not write the code can someone help me please?
n=[-2 -1 0 1 2 3 4];
x=[3 1 0 4 6 2 9]; time scaling, discrete time, property, scaling, time, dsp, stem, matlab MATLAB Answers — New Questions