Category: Matlab
Category Archives: Matlab
Fit data to lagged custom function
Hello,
I would like to ask if you can advice the correct approach I can follow to estimate the parameters of a custom lagged function
(1) y(t)=c^2*a+y(t-1)*(a-1)
where c is a known constant.
to a time series data (I can use the symbilic function to create (1) )
Thank you.
Best regards
PaoloHello,
I would like to ask if you can advice the correct approach I can follow to estimate the parameters of a custom lagged function
(1) y(t)=c^2*a+y(t-1)*(a-1)
where c is a known constant.
to a time series data (I can use the symbilic function to create (1) )
Thank you.
Best regards
Paolo Hello,
I would like to ask if you can advice the correct approach I can follow to estimate the parameters of a custom lagged function
(1) y(t)=c^2*a+y(t-1)*(a-1)
where c is a known constant.
to a time series data (I can use the symbilic function to create (1) )
Thank you.
Best regards
Paolo curve fitting, time series MATLAB Answers — New Questions
Simulink mask: show/hide the port of a custom Simulink block
Hi guys,
I am creating a mask for my custom block and I want add a checkbox with the following behaviour:
checked: it shows a new port the the block
unhecked: it hides the new port for the block
The integrator block has the same behaviour (see the belows images to understand):
I am struggling how to implement this feature in the Checkbox callback because I can’t find the parameter to show/hide the port.Hi guys,
I am creating a mask for my custom block and I want add a checkbox with the following behaviour:
checked: it shows a new port the the block
unhecked: it hides the new port for the block
The integrator block has the same behaviour (see the belows images to understand):
I am struggling how to implement this feature in the Checkbox callback because I can’t find the parameter to show/hide the port. Hi guys,
I am creating a mask for my custom block and I want add a checkbox with the following behaviour:
checked: it shows a new port the the block
unhecked: it hides the new port for the block
The integrator block has the same behaviour (see the belows images to understand):
I am struggling how to implement this feature in the Checkbox callback because I can’t find the parameter to show/hide the port. simulink, mask, integrator, custom MATLAB Answers — New Questions
Compilation Error encountered while running Polyspace Bug Finder.
Version : R2021a
language : C
C version : C11
Compiler : ti
Target : C28x
Project : TMS320F28374s
Error :
—
File D:CCS_workspacePolyspace testPatriotSafetyMonitor_SL1_SL2_20240710_058.000_Gen3C2000_18_12_2_LTS_Includestdlib.h line 294
Error: declaration is incompatible with "long __euclidean_div_i32byu32(long, unsigned long, unsigned long)" (declared at line 50 of "C:Program FilesPolyspaceR2021apolyspaceverifierextensionstitmw_builtinsc28x.h")
__euclidean_div_i32byu32(long numerator, unsigned long denominator);
^
When performing Bug Finder analysis, an incompatibility occurs between Polyspace’s C28x.h and my .h file. However, the same program does not exhibit these issues on some computers. I hope to identify the true cause to ensure the program is error-free. Could you please explain the role of C28x.h in the analysis? Additionally, is it reasonable to modify C28x.h?Version : R2021a
language : C
C version : C11
Compiler : ti
Target : C28x
Project : TMS320F28374s
Error :
—
File D:CCS_workspacePolyspace testPatriotSafetyMonitor_SL1_SL2_20240710_058.000_Gen3C2000_18_12_2_LTS_Includestdlib.h line 294
Error: declaration is incompatible with "long __euclidean_div_i32byu32(long, unsigned long, unsigned long)" (declared at line 50 of "C:Program FilesPolyspaceR2021apolyspaceverifierextensionstitmw_builtinsc28x.h")
__euclidean_div_i32byu32(long numerator, unsigned long denominator);
^
When performing Bug Finder analysis, an incompatibility occurs between Polyspace’s C28x.h and my .h file. However, the same program does not exhibit these issues on some computers. I hope to identify the true cause to ensure the program is error-free. Could you please explain the role of C28x.h in the analysis? Additionally, is it reasonable to modify C28x.h? Version : R2021a
language : C
C version : C11
Compiler : ti
Target : C28x
Project : TMS320F28374s
Error :
—
File D:CCS_workspacePolyspace testPatriotSafetyMonitor_SL1_SL2_20240710_058.000_Gen3C2000_18_12_2_LTS_Includestdlib.h line 294
Error: declaration is incompatible with "long __euclidean_div_i32byu32(long, unsigned long, unsigned long)" (declared at line 50 of "C:Program FilesPolyspaceR2021apolyspaceverifierextensionstitmw_builtinsc28x.h")
__euclidean_div_i32byu32(long numerator, unsigned long denominator);
^
When performing Bug Finder analysis, an incompatibility occurs between Polyspace’s C28x.h and my .h file. However, the same program does not exhibit these issues on some computers. I hope to identify the true cause to ensure the program is error-free. Could you please explain the role of C28x.h in the analysis? Additionally, is it reasonable to modify C28x.h? polyspace, bug finder MATLAB Answers — New Questions
Effect size, statistical power of the test, and confidence interval (of hypothesis testing)
I am using the following two-sample tests for non-normal distributions:
chi2gof
kstest2
ranksum
kruskalwallis
All of them return a p-value, i.e. a p-value for chi2gof, a p-value for kstest2, a p-value for ranksum, and a p-value for kruskalwallis.
Since the p-value is not enough to understand the data/distributions (for example, please see Sullivan & Feinn (2012), Dunkler et al.(2020), Greenland (2016), and du Prel et al. (2009)), I would like to calculate the effect size, the statistical power of the test, and the confidence interval (of hypothesis testing).
I would use the following MATLAB functions:
meanEffectSize (two-sample effect size computations)
sampsizepwr (power of the test)
not found anything about the confidence interval..
However:
I am not sure if both functions, meanEffectSize and sampsizepwr, can be "compatible" with (i) non-normal distributions and (ii) with the 4 previously mentioned tests.
According to the documentation I found on sampsizepwr, it looks like that the calculation of the statistical power of the test works only with normal distributions, but I am not sure.
Those 4 mentioned tests do not provide the confidence interval. Maybe other MATLAB function do, but I was not able to find them.
I have then 2 questions:
Question 1. Is there anyone who could kindly enlighten me on the "compatibility" of meanEffectSize and sampsizepw with with (i) non-normal distributions and (ii) with the 4 previously mentioned tests?
Question 2. Is there anyone who could kindly tell me if there are MATLAB functions to calculate the confidence intervals for the 4 mentioned statistical tests?I am using the following two-sample tests for non-normal distributions:
chi2gof
kstest2
ranksum
kruskalwallis
All of them return a p-value, i.e. a p-value for chi2gof, a p-value for kstest2, a p-value for ranksum, and a p-value for kruskalwallis.
Since the p-value is not enough to understand the data/distributions (for example, please see Sullivan & Feinn (2012), Dunkler et al.(2020), Greenland (2016), and du Prel et al. (2009)), I would like to calculate the effect size, the statistical power of the test, and the confidence interval (of hypothesis testing).
I would use the following MATLAB functions:
meanEffectSize (two-sample effect size computations)
sampsizepwr (power of the test)
not found anything about the confidence interval..
However:
I am not sure if both functions, meanEffectSize and sampsizepwr, can be "compatible" with (i) non-normal distributions and (ii) with the 4 previously mentioned tests.
According to the documentation I found on sampsizepwr, it looks like that the calculation of the statistical power of the test works only with normal distributions, but I am not sure.
Those 4 mentioned tests do not provide the confidence interval. Maybe other MATLAB function do, but I was not able to find them.
I have then 2 questions:
Question 1. Is there anyone who could kindly enlighten me on the "compatibility" of meanEffectSize and sampsizepw with with (i) non-normal distributions and (ii) with the 4 previously mentioned tests?
Question 2. Is there anyone who could kindly tell me if there are MATLAB functions to calculate the confidence intervals for the 4 mentioned statistical tests? I am using the following two-sample tests for non-normal distributions:
chi2gof
kstest2
ranksum
kruskalwallis
All of them return a p-value, i.e. a p-value for chi2gof, a p-value for kstest2, a p-value for ranksum, and a p-value for kruskalwallis.
Since the p-value is not enough to understand the data/distributions (for example, please see Sullivan & Feinn (2012), Dunkler et al.(2020), Greenland (2016), and du Prel et al. (2009)), I would like to calculate the effect size, the statistical power of the test, and the confidence interval (of hypothesis testing).
I would use the following MATLAB functions:
meanEffectSize (two-sample effect size computations)
sampsizepwr (power of the test)
not found anything about the confidence interval..
However:
I am not sure if both functions, meanEffectSize and sampsizepwr, can be "compatible" with (i) non-normal distributions and (ii) with the 4 previously mentioned tests.
According to the documentation I found on sampsizepwr, it looks like that the calculation of the statistical power of the test works only with normal distributions, but I am not sure.
Those 4 mentioned tests do not provide the confidence interval. Maybe other MATLAB function do, but I was not able to find them.
I have then 2 questions:
Question 1. Is there anyone who could kindly enlighten me on the "compatibility" of meanEffectSize and sampsizepw with with (i) non-normal distributions and (ii) with the 4 previously mentioned tests?
Question 2. Is there anyone who could kindly tell me if there are MATLAB functions to calculate the confidence intervals for the 4 mentioned statistical tests? effect size, statistical power, confidence interval, chi2gof, kstest2, ranksum, kruskalwallis MATLAB Answers — New Questions
Tuning ExperienceHorizon hyperparamter for PPO agent (Reinforcement Learning)
Hello everyone,
I’m trying to train a PPO agent, and I would like to change the value for the ExperienceHorizon hyperparameter (Options for PPO agent – MATLAB – MathWorks Switzerland)
When I try another value than the default, the agent wait for the end of the episode to update its policy. For example, ExperienceHorizon=1024 don’t work for me, dispite the episode’s lenght of more than 1024 steps. I’m also not using Parallel training.
I also get the same issue if I change the MiniBatchSize from its default value.
Is there anything I’ve missed about this parameter?
More infos on PPO algorithms: Proximal Policy Optimization (PPO) Agents – MATLAB & Simulink – MathWorks Switzerland
If anyone could help, that would be very nice!
Thanks a lot in advance,
NicolasHello everyone,
I’m trying to train a PPO agent, and I would like to change the value for the ExperienceHorizon hyperparameter (Options for PPO agent – MATLAB – MathWorks Switzerland)
When I try another value than the default, the agent wait for the end of the episode to update its policy. For example, ExperienceHorizon=1024 don’t work for me, dispite the episode’s lenght of more than 1024 steps. I’m also not using Parallel training.
I also get the same issue if I change the MiniBatchSize from its default value.
Is there anything I’ve missed about this parameter?
More infos on PPO algorithms: Proximal Policy Optimization (PPO) Agents – MATLAB & Simulink – MathWorks Switzerland
If anyone could help, that would be very nice!
Thanks a lot in advance,
Nicolas Hello everyone,
I’m trying to train a PPO agent, and I would like to change the value for the ExperienceHorizon hyperparameter (Options for PPO agent – MATLAB – MathWorks Switzerland)
When I try another value than the default, the agent wait for the end of the episode to update its policy. For example, ExperienceHorizon=1024 don’t work for me, dispite the episode’s lenght of more than 1024 steps. I’m also not using Parallel training.
I also get the same issue if I change the MiniBatchSize from its default value.
Is there anything I’ve missed about this parameter?
More infos on PPO algorithms: Proximal Policy Optimization (PPO) Agents – MATLAB & Simulink – MathWorks Switzerland
If anyone could help, that would be very nice!
Thanks a lot in advance,
Nicolas ppo agents, reinforcement learning, experience horizon MATLAB Answers — New Questions
is it possible to see what variables and functions affecting a certain variable ?
hello everyone,
i am having a little problem, i need to figure out what affects one variable. that variable is in a for loop, which is in a function, which is also in a function and several values are also calculated by several other functions…
i do know i can have a chart what functions are involved and how they are affect each other, when i have a project. however, i cant see the variables there, or if i dont know how.
so thats my question, how can i see the functions AND variables that affect one variable.hello everyone,
i am having a little problem, i need to figure out what affects one variable. that variable is in a for loop, which is in a function, which is also in a function and several values are also calculated by several other functions…
i do know i can have a chart what functions are involved and how they are affect each other, when i have a project. however, i cant see the variables there, or if i dont know how.
so thats my question, how can i see the functions AND variables that affect one variable. hello everyone,
i am having a little problem, i need to figure out what affects one variable. that variable is in a for loop, which is in a function, which is also in a function and several values are also calculated by several other functions…
i do know i can have a chart what functions are involved and how they are affect each other, when i have a project. however, i cant see the variables there, or if i dont know how.
so thats my question, how can i see the functions AND variables that affect one variable. variable, function MATLAB Answers — New Questions
lung segmentation in MR-Dataset
Hello,
does anybody know a way to segment Lungs from mri-dataset? I foud many ways to segment them in CT, but not in MR.
I tried the otsu and the k-means methods, but the heart is alway segmented with the lungsHello,
does anybody know a way to segment Lungs from mri-dataset? I foud many ways to segment them in CT, but not in MR.
I tried the otsu and the k-means methods, but the heart is alway segmented with the lungs Hello,
does anybody know a way to segment Lungs from mri-dataset? I foud many ways to segment them in CT, but not in MR.
I tried the otsu and the k-means methods, but the heart is alway segmented with the lungs image segmentation, image processing, lung, mri MATLAB Answers — New Questions
error about MATLAB Runtime 7.5 download
I want to download the MATLAB Runtime (MCR) 7.5 version.
However, when I run the .exe file, I get the following warning.
"Error 1723. There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support or package vendor"
Is there a solution to this?I want to download the MATLAB Runtime (MCR) 7.5 version.
However, when I run the .exe file, I get the following warning.
"Error 1723. There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support or package vendor"
Is there a solution to this? I want to download the MATLAB Runtime (MCR) 7.5 version.
However, when I run the .exe file, I get the following warning.
"Error 1723. There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support or package vendor"
Is there a solution to this? mcr MATLAB Answers — New Questions
How to use modern features (notably std::unique_ptr) in the C++ code of my S-functions while using the linaro v4.8 toolchain in embedded coder?
Background
I am using simulink with S-functions containing custom C++ code. My simulink model runs on an ARM board running Linux, using embedded coder. My C++ code uses unique pointers (std::unique_ptr). The toolchain I use is Linaro v4.8.
The error
I get the following error when building the Linux executable using the simulink ‘build’ button:
C:/my_path/cpp/src/my_class.h:13:5: error: ‘unique_ptr’ in namespace ‘std’ does not name a type
My idea
I suspect that the C++ version being compiled to is < c++11, and I would like to force the g++ compiler to compile the code using c++11. I can’t change compiler flags in the simulink menu, it is grayed out.
I found the linaro toolchain xml file and changed compiler flags there, but when I look at the compiler command generated in simulink I do not see the -std=c++11 compiler flag anywhere.
The question
How can I use modern features (notably std::unique_ptr) in the C++ code of my S-functions while using the linaro v4.8 toolchain in simulink embedded coder?Background
I am using simulink with S-functions containing custom C++ code. My simulink model runs on an ARM board running Linux, using embedded coder. My C++ code uses unique pointers (std::unique_ptr). The toolchain I use is Linaro v4.8.
The error
I get the following error when building the Linux executable using the simulink ‘build’ button:
C:/my_path/cpp/src/my_class.h:13:5: error: ‘unique_ptr’ in namespace ‘std’ does not name a type
My idea
I suspect that the C++ version being compiled to is < c++11, and I would like to force the g++ compiler to compile the code using c++11. I can’t change compiler flags in the simulink menu, it is grayed out.
I found the linaro toolchain xml file and changed compiler flags there, but when I look at the compiler command generated in simulink I do not see the -std=c++11 compiler flag anywhere.
The question
How can I use modern features (notably std::unique_ptr) in the C++ code of my S-functions while using the linaro v4.8 toolchain in simulink embedded coder? Background
I am using simulink with S-functions containing custom C++ code. My simulink model runs on an ARM board running Linux, using embedded coder. My C++ code uses unique pointers (std::unique_ptr). The toolchain I use is Linaro v4.8.
The error
I get the following error when building the Linux executable using the simulink ‘build’ button:
C:/my_path/cpp/src/my_class.h:13:5: error: ‘unique_ptr’ in namespace ‘std’ does not name a type
My idea
I suspect that the C++ version being compiled to is < c++11, and I would like to force the g++ compiler to compile the code using c++11. I can’t change compiler flags in the simulink menu, it is grayed out.
I found the linaro toolchain xml file and changed compiler flags there, but when I look at the compiler command generated in simulink I do not see the -std=c++11 compiler flag anywhere.
The question
How can I use modern features (notably std::unique_ptr) in the C++ code of my S-functions while using the linaro v4.8 toolchain in simulink embedded coder? embedded coder, s-function, simulink, linux MATLAB Answers — New Questions
copping grayscale image and remove any other borders or details
could you please help me to get only the gray scale images without any borders and without any written words or letters created by the device . i want a general code to do this beause i have other images with other border thickness and other written , and i want the gray image entire only
@Image Analyst
Image Analystcould you please help me to get only the gray scale images without any borders and without any written words or letters created by the device . i want a general code to do this beause i have other images with other border thickness and other written , and i want the gray image entire only
@Image Analyst
Image Analyst could you please help me to get only the gray scale images without any borders and without any written words or letters created by the device . i want a general code to do this beause i have other images with other border thickness and other written , and i want the gray image entire only
@Image Analyst
Image Analyst image analyst MATLAB Answers — New Questions
Design a feedback controller to control pH value of a non linear system
Hi all!.
I am working on a question where we calculate an optimal dosage using multiple sensor inputs. Then we send the calculated dosage to the plant and we monitor the pH value. Right now we have an open loop system. I want to maintain the output pH value in a range of 5.2 to 5.8 by introducing a feedback and a PID controller.
I have previous data about the dosage we calculated and the resulted pH values.Hi all!.
I am working on a question where we calculate an optimal dosage using multiple sensor inputs. Then we send the calculated dosage to the plant and we monitor the pH value. Right now we have an open loop system. I want to maintain the output pH value in a range of 5.2 to 5.8 by introducing a feedback and a PID controller.
I have previous data about the dosage we calculated and the resulted pH values. Hi all!.
I am working on a question where we calculate an optimal dosage using multiple sensor inputs. Then we send the calculated dosage to the plant and we monitor the pH value. Right now we have an open loop system. I want to maintain the output pH value in a range of 5.2 to 5.8 by introducing a feedback and a PID controller.
I have previous data about the dosage we calculated and the resulted pH values. pid, ph, feedback control MATLAB Answers — New Questions
wt is the Activation Key for activating MATLAB Simulink
Activation KeyActivation Key Activation Key provide activation key for matlab MATLAB Answers — New Questions
vgg16 not installed as Deep learning toolbox has missing this package
Error using vgg16 (line 60)
vgg16 requires the Deep Learning Toolbox Model for VGG-16 Network support package. To install this support package, use the Add-On Explorer.
How can we run the program without package installed? Is there any solution?Error using vgg16 (line 60)
vgg16 requires the Deep Learning Toolbox Model for VGG-16 Network support package. To install this support package, use the Add-On Explorer.
How can we run the program without package installed? Is there any solution? Error using vgg16 (line 60)
vgg16 requires the Deep Learning Toolbox Model for VGG-16 Network support package. To install this support package, use the Add-On Explorer.
How can we run the program without package installed? Is there any solution? neural network model, vgg16 MATLAB Answers — New Questions
Using FFT Coefficients/Descriptors to reconstruct particle shape
Hi, I am trying to use Fourier descriptors to reconstruct the shape of a particle. I have written most of the code (with a lot of help) and only the last step which involves using Fourier descriptors to reconstruct the shape of the original image remains.
I need help to know which functions to use to achieve this. I would really appreciate if anyone could help.
Here is the code:
I have also attached the original image and another file which demonstrates what I need to do.
scale_factor = 100/90; % (units: microns/pixel)
% to convert pixels to microns,
% multiply # of pixels by scale_factor
%1. Open and show image of particle
img = imread(‘1_50.JPG’); %Read image
subplot (3,3,1)
imshow(img) %show image
%2. Binarize and show image
BW = im2bw(img,0.45); %binarize image with a threshold value of 0.45
img1= bwareaopen (BW, 1000); %Remove small objects
img2= imfill(img1, ‘holes’); %fill holes
subplot(3,3,2)
imshow(img2) %show binarized image
%3. Setting up the axes
% for plotting into multiple axes in one loop, it’s convenient to set up
% all the axes first, before anything is plotted into them
% 3.1. set up the 2nd axes:
ax3 = subplot(3,3,3);
hold on
box on %draws a box that encompasses the entire axes area
axis image %sets the aspect ratio of the axes (ax2) to be equal and
%adjusts the limits of the axes so that the data units are
%of equal size along both the x-axis and y-axis.
set(ax3,’YDir’,’reverse’) %reverses the y-axis to begin from the top
%since the origin of the image is at the top left-corner
% 3.2. set up the 3rd axes:
ax4 = subplot(3,3,4);
hold on
%4. Compute centroid of binarized image
centriod_value= regionprops(img2, ‘Centroid’); %Finds centroid of image
centroid = cat(1,centriod_value.Centroid); %Stores centroid coordinates in a two-column matrix
%5. Tracing the boundary of image
p_boundary= bwboundaries(img2); % trace the exterior boundaries of particle
%(in row, column order, not x,y)
number_of_boundaries = size(p_boundary,1); %specify only one boundary
centroid = centroid*scale_factor;
% 6. Setting up equally spaced angles before initing the loop
%use 129 points to have an angle spacing of 360/128
N_angles = 129;
interp_angles = linspace(0,360,N_angles).’;
%7. Initiate for loop to plot boundary, centroid, & a graph of radius vs angle
for k = 1 : number_of_boundaries % initiate loop to go round the selected boundary
thisBoundary = p_boundary{k}*scale_factor;
y = thisBoundary(:,1); % rows
x = thisBoundary(:,2); % columns
plot(ax3, x, y, ‘g’, ‘LineWidth’, 2);
plot(ax3, centroid(:,1),centroid(:,2),’b.’)
% 7.1. Calculate the angles in degrees
deltaY = thisBoundary(:,1) – centroid(k,2); % boundary(:,1) is y, but centroid(k,2) is y
deltaX = thisBoundary(:,2) – centroid(k,1); % boundary(:,2) is x, but centroid(k,1) is x
% angles = atand(deltaY ./ deltaX); % atand gives angles in range [-90,90]
angles = atan2d(deltaY,deltaX); % use atan2d to get angles in range [-180,180]
% 7.2. Calculate the radii
radius = sqrt(deltaY.^2 + deltaX.^2); % use deltaX and deltaY, which were just calculated
% 7.3. Add 360 degrees to negative angles so that range is [0,360] instead of [-180,180]
idx = angles < 0; %idx reps angles less than 0 degreees
angles(idx) = angles(idx)+360; %360 degrees is added to idx angles
%7.4. Sort angles in ascending order
% sort the angles, so the first one is smallest (closest to zero)
% and the last one is largest (closest to 360)
% this is useful for getting a smooth line that goes from 0 to 360 in the plot
% I returns the corresponding indices of the angles
[angles,I] = sort(angles);
%7.5. Reorder distances the same way angles was reordered using I
radius = radius(I);
%7.6. Use only unique angles in case an angle is repeated
% in case any angles are repeated, use only the unique set and
% corresponding distances in interp1 (in this data, one angle is
% repeated twice, with the same distance each time)
%The ~ (tilde) here is a placeholder indicating that we’re not interested
%in capturing the actual unique elements, only their indices
[~,I] = unique(angles);
% 7.7. perform linear interpolation/extrapolation:
%angles(I)= sample points, radius(I)= correspoinding points
%and interp_angles = coordinates of the querry points (QP)
%In general, the functions returns interpolated values at specific QP
interp_distances = interp1(angles(I),radius(I),interp_angles,’linear’,’extrap’);
% 7.8 Plot distance vs. angle.
plot(ax4,interp_angles,interp_distances)
end
%8. Apply fft algorithm to values of radius
L = length(interp_distances); %Define the number of the radiuses (points)
f = 0:L-1; %Define the sampling frequencies
A = fft(interp_distances); %Transforming the radius function into frequency domain using FFT
B = (abs(A)/2535.2); % Normalize the amplitude of fourier descriptors using the first descriptors
%9. Plot fft descriptor vs. frequency
subplot(3,3,5)
bar(f,B,3) %plot the frequencies vs. the nornalised descriptors
xlim([0 128])
%10. Plot phase angle vs. frequency
subplot(3,3,6)
bar(f, angle(A),3) % plot the frequencies vs phase angles
xlim([0 128])
ylim([-4 4])
%11. Create a table of values
table1 = table(A, f’, abs(A), B, angle(A));
table1.Properties.VariableNames = {‘FFT_coeffs’, ‘Frequency’, ‘Amplitude’, ‘Norm_Amplitude’ ‘Phase’};
disp(table1);
%12. Reconstruct particle boundary using FFT descriptors ?????Hi, I am trying to use Fourier descriptors to reconstruct the shape of a particle. I have written most of the code (with a lot of help) and only the last step which involves using Fourier descriptors to reconstruct the shape of the original image remains.
I need help to know which functions to use to achieve this. I would really appreciate if anyone could help.
Here is the code:
I have also attached the original image and another file which demonstrates what I need to do.
scale_factor = 100/90; % (units: microns/pixel)
% to convert pixels to microns,
% multiply # of pixels by scale_factor
%1. Open and show image of particle
img = imread(‘1_50.JPG’); %Read image
subplot (3,3,1)
imshow(img) %show image
%2. Binarize and show image
BW = im2bw(img,0.45); %binarize image with a threshold value of 0.45
img1= bwareaopen (BW, 1000); %Remove small objects
img2= imfill(img1, ‘holes’); %fill holes
subplot(3,3,2)
imshow(img2) %show binarized image
%3. Setting up the axes
% for plotting into multiple axes in one loop, it’s convenient to set up
% all the axes first, before anything is plotted into them
% 3.1. set up the 2nd axes:
ax3 = subplot(3,3,3);
hold on
box on %draws a box that encompasses the entire axes area
axis image %sets the aspect ratio of the axes (ax2) to be equal and
%adjusts the limits of the axes so that the data units are
%of equal size along both the x-axis and y-axis.
set(ax3,’YDir’,’reverse’) %reverses the y-axis to begin from the top
%since the origin of the image is at the top left-corner
% 3.2. set up the 3rd axes:
ax4 = subplot(3,3,4);
hold on
%4. Compute centroid of binarized image
centriod_value= regionprops(img2, ‘Centroid’); %Finds centroid of image
centroid = cat(1,centriod_value.Centroid); %Stores centroid coordinates in a two-column matrix
%5. Tracing the boundary of image
p_boundary= bwboundaries(img2); % trace the exterior boundaries of particle
%(in row, column order, not x,y)
number_of_boundaries = size(p_boundary,1); %specify only one boundary
centroid = centroid*scale_factor;
% 6. Setting up equally spaced angles before initing the loop
%use 129 points to have an angle spacing of 360/128
N_angles = 129;
interp_angles = linspace(0,360,N_angles).’;
%7. Initiate for loop to plot boundary, centroid, & a graph of radius vs angle
for k = 1 : number_of_boundaries % initiate loop to go round the selected boundary
thisBoundary = p_boundary{k}*scale_factor;
y = thisBoundary(:,1); % rows
x = thisBoundary(:,2); % columns
plot(ax3, x, y, ‘g’, ‘LineWidth’, 2);
plot(ax3, centroid(:,1),centroid(:,2),’b.’)
% 7.1. Calculate the angles in degrees
deltaY = thisBoundary(:,1) – centroid(k,2); % boundary(:,1) is y, but centroid(k,2) is y
deltaX = thisBoundary(:,2) – centroid(k,1); % boundary(:,2) is x, but centroid(k,1) is x
% angles = atand(deltaY ./ deltaX); % atand gives angles in range [-90,90]
angles = atan2d(deltaY,deltaX); % use atan2d to get angles in range [-180,180]
% 7.2. Calculate the radii
radius = sqrt(deltaY.^2 + deltaX.^2); % use deltaX and deltaY, which were just calculated
% 7.3. Add 360 degrees to negative angles so that range is [0,360] instead of [-180,180]
idx = angles < 0; %idx reps angles less than 0 degreees
angles(idx) = angles(idx)+360; %360 degrees is added to idx angles
%7.4. Sort angles in ascending order
% sort the angles, so the first one is smallest (closest to zero)
% and the last one is largest (closest to 360)
% this is useful for getting a smooth line that goes from 0 to 360 in the plot
% I returns the corresponding indices of the angles
[angles,I] = sort(angles);
%7.5. Reorder distances the same way angles was reordered using I
radius = radius(I);
%7.6. Use only unique angles in case an angle is repeated
% in case any angles are repeated, use only the unique set and
% corresponding distances in interp1 (in this data, one angle is
% repeated twice, with the same distance each time)
%The ~ (tilde) here is a placeholder indicating that we’re not interested
%in capturing the actual unique elements, only their indices
[~,I] = unique(angles);
% 7.7. perform linear interpolation/extrapolation:
%angles(I)= sample points, radius(I)= correspoinding points
%and interp_angles = coordinates of the querry points (QP)
%In general, the functions returns interpolated values at specific QP
interp_distances = interp1(angles(I),radius(I),interp_angles,’linear’,’extrap’);
% 7.8 Plot distance vs. angle.
plot(ax4,interp_angles,interp_distances)
end
%8. Apply fft algorithm to values of radius
L = length(interp_distances); %Define the number of the radiuses (points)
f = 0:L-1; %Define the sampling frequencies
A = fft(interp_distances); %Transforming the radius function into frequency domain using FFT
B = (abs(A)/2535.2); % Normalize the amplitude of fourier descriptors using the first descriptors
%9. Plot fft descriptor vs. frequency
subplot(3,3,5)
bar(f,B,3) %plot the frequencies vs. the nornalised descriptors
xlim([0 128])
%10. Plot phase angle vs. frequency
subplot(3,3,6)
bar(f, angle(A),3) % plot the frequencies vs phase angles
xlim([0 128])
ylim([-4 4])
%11. Create a table of values
table1 = table(A, f’, abs(A), B, angle(A));
table1.Properties.VariableNames = {‘FFT_coeffs’, ‘Frequency’, ‘Amplitude’, ‘Norm_Amplitude’ ‘Phase’};
disp(table1);
%12. Reconstruct particle boundary using FFT descriptors ????? Hi, I am trying to use Fourier descriptors to reconstruct the shape of a particle. I have written most of the code (with a lot of help) and only the last step which involves using Fourier descriptors to reconstruct the shape of the original image remains.
I need help to know which functions to use to achieve this. I would really appreciate if anyone could help.
Here is the code:
I have also attached the original image and another file which demonstrates what I need to do.
scale_factor = 100/90; % (units: microns/pixel)
% to convert pixels to microns,
% multiply # of pixels by scale_factor
%1. Open and show image of particle
img = imread(‘1_50.JPG’); %Read image
subplot (3,3,1)
imshow(img) %show image
%2. Binarize and show image
BW = im2bw(img,0.45); %binarize image with a threshold value of 0.45
img1= bwareaopen (BW, 1000); %Remove small objects
img2= imfill(img1, ‘holes’); %fill holes
subplot(3,3,2)
imshow(img2) %show binarized image
%3. Setting up the axes
% for plotting into multiple axes in one loop, it’s convenient to set up
% all the axes first, before anything is plotted into them
% 3.1. set up the 2nd axes:
ax3 = subplot(3,3,3);
hold on
box on %draws a box that encompasses the entire axes area
axis image %sets the aspect ratio of the axes (ax2) to be equal and
%adjusts the limits of the axes so that the data units are
%of equal size along both the x-axis and y-axis.
set(ax3,’YDir’,’reverse’) %reverses the y-axis to begin from the top
%since the origin of the image is at the top left-corner
% 3.2. set up the 3rd axes:
ax4 = subplot(3,3,4);
hold on
%4. Compute centroid of binarized image
centriod_value= regionprops(img2, ‘Centroid’); %Finds centroid of image
centroid = cat(1,centriod_value.Centroid); %Stores centroid coordinates in a two-column matrix
%5. Tracing the boundary of image
p_boundary= bwboundaries(img2); % trace the exterior boundaries of particle
%(in row, column order, not x,y)
number_of_boundaries = size(p_boundary,1); %specify only one boundary
centroid = centroid*scale_factor;
% 6. Setting up equally spaced angles before initing the loop
%use 129 points to have an angle spacing of 360/128
N_angles = 129;
interp_angles = linspace(0,360,N_angles).’;
%7. Initiate for loop to plot boundary, centroid, & a graph of radius vs angle
for k = 1 : number_of_boundaries % initiate loop to go round the selected boundary
thisBoundary = p_boundary{k}*scale_factor;
y = thisBoundary(:,1); % rows
x = thisBoundary(:,2); % columns
plot(ax3, x, y, ‘g’, ‘LineWidth’, 2);
plot(ax3, centroid(:,1),centroid(:,2),’b.’)
% 7.1. Calculate the angles in degrees
deltaY = thisBoundary(:,1) – centroid(k,2); % boundary(:,1) is y, but centroid(k,2) is y
deltaX = thisBoundary(:,2) – centroid(k,1); % boundary(:,2) is x, but centroid(k,1) is x
% angles = atand(deltaY ./ deltaX); % atand gives angles in range [-90,90]
angles = atan2d(deltaY,deltaX); % use atan2d to get angles in range [-180,180]
% 7.2. Calculate the radii
radius = sqrt(deltaY.^2 + deltaX.^2); % use deltaX and deltaY, which were just calculated
% 7.3. Add 360 degrees to negative angles so that range is [0,360] instead of [-180,180]
idx = angles < 0; %idx reps angles less than 0 degreees
angles(idx) = angles(idx)+360; %360 degrees is added to idx angles
%7.4. Sort angles in ascending order
% sort the angles, so the first one is smallest (closest to zero)
% and the last one is largest (closest to 360)
% this is useful for getting a smooth line that goes from 0 to 360 in the plot
% I returns the corresponding indices of the angles
[angles,I] = sort(angles);
%7.5. Reorder distances the same way angles was reordered using I
radius = radius(I);
%7.6. Use only unique angles in case an angle is repeated
% in case any angles are repeated, use only the unique set and
% corresponding distances in interp1 (in this data, one angle is
% repeated twice, with the same distance each time)
%The ~ (tilde) here is a placeholder indicating that we’re not interested
%in capturing the actual unique elements, only their indices
[~,I] = unique(angles);
% 7.7. perform linear interpolation/extrapolation:
%angles(I)= sample points, radius(I)= correspoinding points
%and interp_angles = coordinates of the querry points (QP)
%In general, the functions returns interpolated values at specific QP
interp_distances = interp1(angles(I),radius(I),interp_angles,’linear’,’extrap’);
% 7.8 Plot distance vs. angle.
plot(ax4,interp_angles,interp_distances)
end
%8. Apply fft algorithm to values of radius
L = length(interp_distances); %Define the number of the radiuses (points)
f = 0:L-1; %Define the sampling frequencies
A = fft(interp_distances); %Transforming the radius function into frequency domain using FFT
B = (abs(A)/2535.2); % Normalize the amplitude of fourier descriptors using the first descriptors
%9. Plot fft descriptor vs. frequency
subplot(3,3,5)
bar(f,B,3) %plot the frequencies vs. the nornalised descriptors
xlim([0 128])
%10. Plot phase angle vs. frequency
subplot(3,3,6)
bar(f, angle(A),3) % plot the frequencies vs phase angles
xlim([0 128])
ylim([-4 4])
%11. Create a table of values
table1 = table(A, f’, abs(A), B, angle(A));
table1.Properties.VariableNames = {‘FFT_coeffs’, ‘Frequency’, ‘Amplitude’, ‘Norm_Amplitude’ ‘Phase’};
disp(table1);
%12. Reconstruct particle boundary using FFT descriptors ????? fft, shape reconstruction, fourier descriptor MATLAB Answers — New Questions
How to treat 200 rows of data as an event when constructing a Timetable, as a piece of data, the size is 200*1
There is a table, if the sampling rate is set to 200 when constructing the Timetable,TT = timetable(var,’SampleRate’,200) ,then the time of each row of the Timetable is 0.005s, 0.01s etc, but what I want is that the time of each row is 1s, 2s, 3s, and the corresponding var data shape of each row is 200*1, what should I do?There is a table, if the sampling rate is set to 200 when constructing the Timetable,TT = timetable(var,’SampleRate’,200) ,then the time of each row of the Timetable is 0.005s, 0.01s etc, but what I want is that the time of each row is 1s, 2s, 3s, and the corresponding var data shape of each row is 200*1, what should I do? There is a table, if the sampling rate is set to 200 when constructing the Timetable,TT = timetable(var,’SampleRate’,200) ,then the time of each row of the Timetable is 0.005s, 0.01s etc, but what I want is that the time of each row is 1s, 2s, 3s, and the corresponding var data shape of each row is 200*1, what should I do? timetable MATLAB Answers — New Questions
My question is what is the value i am getting as the output of my code.
syms x
eqn = 0.5959 + 0.0321*(x^2.1)-0.184*(x^8)+0.0143*(x^2.5)-0.2359*(sqrt((1-x^4)/x^4));
solve(eqn == 0,x)
the results are given assyms x
eqn = 0.5959 + 0.0321*(x^2.1)-0.184*(x^8)+0.0143*(x^2.5)-0.2359*(sqrt((1-x^4)/x^4));
solve(eqn == 0,x)
the results are given as syms x
eqn = 0.5959 + 0.0321*(x^2.1)-0.184*(x^8)+0.0143*(x^2.5)-0.2359*(sqrt((1-x^4)/x^4));
solve(eqn == 0,x)
the results are given as linear equation MATLAB Answers — New Questions
TI C2000 f28388d SPI Tx and SPI Rx with multiple chip select GPIOs
My application requires connecting SPI to multiple devices using multiple chip select GPIOs. I tried to make the "Chip select pin" as a variable but it didn’t work. How can I implement this use case with multiple chip selects?My application requires connecting SPI to multiple devices using multiple chip select GPIOs. I tried to make the "Chip select pin" as a variable but it didn’t work. How can I implement this use case with multiple chip selects? My application requires connecting SPI to multiple devices using multiple chip select GPIOs. I tried to make the "Chip select pin" as a variable but it didn’t work. How can I implement this use case with multiple chip selects? spi, tms320f28388d MATLAB Answers — New Questions
Invalid setting in ‘Model’ for parameter ‘Gain’.
I am trying to tune a PID controller for controlling a plant model buit in Simulink. My aim is to obtain the gains of the PID controller using an optimization technique whose code is written in a script file. So, the objective function is calculated by obtaining the loged values from the simulink model. While I run my code, it always shows the error: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’, where the simulink file’s name is Model. Since I am tuning the gains using optimization, the are changing in each iteration. Kp, Ki, and Kd are the gains. The error is: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’.
function objective_func = F3(x)
Kp=x(1)
Ki=x(2)
Kd=x(3)
mdl = "Model";
open_system(mdl)
in = Simulink.SimulationInput(mdl)
out = sim(in)
simout = out.J(3001) %objective function value
objective_func=simout;
endI am trying to tune a PID controller for controlling a plant model buit in Simulink. My aim is to obtain the gains of the PID controller using an optimization technique whose code is written in a script file. So, the objective function is calculated by obtaining the loged values from the simulink model. While I run my code, it always shows the error: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’, where the simulink file’s name is Model. Since I am tuning the gains using optimization, the are changing in each iteration. Kp, Ki, and Kd are the gains. The error is: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’.
function objective_func = F3(x)
Kp=x(1)
Ki=x(2)
Kd=x(3)
mdl = "Model";
open_system(mdl)
in = Simulink.SimulationInput(mdl)
out = sim(in)
simout = out.J(3001) %objective function value
objective_func=simout;
end I am trying to tune a PID controller for controlling a plant model buit in Simulink. My aim is to obtain the gains of the PID controller using an optimization technique whose code is written in a script file. So, the objective function is calculated by obtaining the loged values from the simulink model. While I run my code, it always shows the error: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’, where the simulink file’s name is Model. Since I am tuning the gains using optimization, the are changing in each iteration. Kp, Ki, and Kd are the gains. The error is: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’.
function objective_func = F3(x)
Kp=x(1)
Ki=x(2)
Kd=x(3)
mdl = "Model";
open_system(mdl)
in = Simulink.SimulationInput(mdl)
out = sim(in)
simout = out.J(3001) %objective function value
objective_func=simout;
end simulink, gain block, optimization MATLAB Answers — New Questions
Interpolation of two-dimensional within a given space window
Dear all
I am attaching a dataset, called "Points.txt", where the first and second columns represent the spatial coordinates along the x- and y-th directions, respectively, and the third column the value of a variable at each listed pair of points (x,y). I was wondering which could be a good way to increase the number of points mainly inside the hexagonal shape within the current listed points are restricted to:
I have tried the following:
pgon=nsidedpoly(6,’Center’,[0 0],’SideLength’,1);
%% Let’s rearrange the data associated to the interlayer isotropic exchange, Jinter
% Let’s load the preliminar data
Jinter=cell2mat(struct2cell(load(strcat(pwd,’Preliminar-DataJinter.mat’))));
% Let’s construct the unit vectors of the in-plane unit cell
x=unique(Jinter(:,1));
y=unique(Jinter(:,2));
a1_points=[max(x) 0];
a2_points=[-0.5 max(y)];
a1_modulus=sqrt(dot(a1_points,a1_points));
a2_modulus=sqrt(dot(a2_points,a2_points));
a1=a1_points./a1_modulus;
a2=a2_points./a2_modulus;
% Let’s construct the supercell for Jinter
diff_y=max(y)-min(y);
counter=0;
for dy=[-1 0 1]
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)++dy*[0 1]*diff_y)~=any(Jinter(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+dy*[0 1]*diff_y;
Jinter_extended(counter,3)=Jinter(i,3);
end
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
clear a1 a2 a1_modulus a2_modulus a1_points a2_points Jinter diff_y x y dy
% Let’s plot it
u17=figure(17)
scatter(Jinter_extended(:,1),Jinter_extended(:,2),[],Jinter_extended(:,3),’o’,’filled’);
colormap(gca,bluewhitered(256));
clim([min(Jinter_extended(:,3)) max(Jinter_extended(:,3))]);
clr17=colorbar;
box on;
pbaspect([1 6/4 1]);
clear u17 clr17
% Now, let’s interpolate data
x_extended=linspace(min(Jinter_extended(:,1)),max(Jinter_extended(:,1)));
y_extended=linspace(min(Jinter_extended(:,2)),max(Jinter_extended(:,2)));
Jinter_interpolated=RegularizeData3D(Jinter_extended(:,1),Jinter_extended(:,2),Jinter_extended(:,3),x_extended,y_extended,’interp’,’bicubic’,’smoothness’,1e-4);
x_interpolation=linspace(-1,1,201);
y_interpolation=linspace(-sqrt(3)/2,sqrt(3)/2,201);
[X,Y]=meshgrid(x_interpolation,y_interpolation);
interpolated_Jinter=interp2(x_extended,y_extended,Jinter_interpolated,X,Y,’cubic’);
clear X Y Jinter_interpolated x_extended y_extended Jinter_extended
% Let’s plot it
u18=figure(18)
uimagesc(x_interpolation,y_interpolation,interpolated_Jinter);
colormap(gca,bluewhitered(256));
% hold on
axis xy;
% plot(pgon);
clim([min(min(interpolated_Jinter)) max(max(interpolated_Jinter))]);
clr18=colorbar;
box on;
pbaspect([1 sqrt(3)/2 1]);
clear u18 clr18
% Now, let’s rearrange and save the data
x_intermediate=linspace(-100,100,201);
y_intermediate=linspace(-100,100,201);
counter=0;
for i=1:length(x_interpolation)
for j=1:length(y_interpolation)
counter=counter+1;
Jinter_save(counter,1)=x_intermediate(i);
Jinter_save(counter,2)=y_intermediate(j);
Jinter_save(counter,3)=interpolated_Jinter(i,j);
end
end
writematrix(Jinter_save,strcat(pwd,’Interpolated-DataInterpolated_J_Inter.txt’),’Delimiter’,’space’);
clear interpolated_Jinter Jinter_save x_interpolation y_interpolation counter i j x_intermediate y_intermediate
where the "Jinter.mat" is exactly the same dataset as in "Points.txt". The problem with this is that, for example, if I take a look at the generated "Interpolated_J_Inter.txt", the value for (0,0) differs notably.
Any ideas?Dear all
I am attaching a dataset, called "Points.txt", where the first and second columns represent the spatial coordinates along the x- and y-th directions, respectively, and the third column the value of a variable at each listed pair of points (x,y). I was wondering which could be a good way to increase the number of points mainly inside the hexagonal shape within the current listed points are restricted to:
I have tried the following:
pgon=nsidedpoly(6,’Center’,[0 0],’SideLength’,1);
%% Let’s rearrange the data associated to the interlayer isotropic exchange, Jinter
% Let’s load the preliminar data
Jinter=cell2mat(struct2cell(load(strcat(pwd,’Preliminar-DataJinter.mat’))));
% Let’s construct the unit vectors of the in-plane unit cell
x=unique(Jinter(:,1));
y=unique(Jinter(:,2));
a1_points=[max(x) 0];
a2_points=[-0.5 max(y)];
a1_modulus=sqrt(dot(a1_points,a1_points));
a2_modulus=sqrt(dot(a2_points,a2_points));
a1=a1_points./a1_modulus;
a2=a2_points./a2_modulus;
% Let’s construct the supercell for Jinter
diff_y=max(y)-min(y);
counter=0;
for dy=[-1 0 1]
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)++dy*[0 1]*diff_y)~=any(Jinter(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+dy*[0 1]*diff_y;
Jinter_extended(counter,3)=Jinter(i,3);
end
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
clear a1 a2 a1_modulus a2_modulus a1_points a2_points Jinter diff_y x y dy
% Let’s plot it
u17=figure(17)
scatter(Jinter_extended(:,1),Jinter_extended(:,2),[],Jinter_extended(:,3),’o’,’filled’);
colormap(gca,bluewhitered(256));
clim([min(Jinter_extended(:,3)) max(Jinter_extended(:,3))]);
clr17=colorbar;
box on;
pbaspect([1 6/4 1]);
clear u17 clr17
% Now, let’s interpolate data
x_extended=linspace(min(Jinter_extended(:,1)),max(Jinter_extended(:,1)));
y_extended=linspace(min(Jinter_extended(:,2)),max(Jinter_extended(:,2)));
Jinter_interpolated=RegularizeData3D(Jinter_extended(:,1),Jinter_extended(:,2),Jinter_extended(:,3),x_extended,y_extended,’interp’,’bicubic’,’smoothness’,1e-4);
x_interpolation=linspace(-1,1,201);
y_interpolation=linspace(-sqrt(3)/2,sqrt(3)/2,201);
[X,Y]=meshgrid(x_interpolation,y_interpolation);
interpolated_Jinter=interp2(x_extended,y_extended,Jinter_interpolated,X,Y,’cubic’);
clear X Y Jinter_interpolated x_extended y_extended Jinter_extended
% Let’s plot it
u18=figure(18)
uimagesc(x_interpolation,y_interpolation,interpolated_Jinter);
colormap(gca,bluewhitered(256));
% hold on
axis xy;
% plot(pgon);
clim([min(min(interpolated_Jinter)) max(max(interpolated_Jinter))]);
clr18=colorbar;
box on;
pbaspect([1 sqrt(3)/2 1]);
clear u18 clr18
% Now, let’s rearrange and save the data
x_intermediate=linspace(-100,100,201);
y_intermediate=linspace(-100,100,201);
counter=0;
for i=1:length(x_interpolation)
for j=1:length(y_interpolation)
counter=counter+1;
Jinter_save(counter,1)=x_intermediate(i);
Jinter_save(counter,2)=y_intermediate(j);
Jinter_save(counter,3)=interpolated_Jinter(i,j);
end
end
writematrix(Jinter_save,strcat(pwd,’Interpolated-DataInterpolated_J_Inter.txt’),’Delimiter’,’space’);
clear interpolated_Jinter Jinter_save x_interpolation y_interpolation counter i j x_intermediate y_intermediate
where the "Jinter.mat" is exactly the same dataset as in "Points.txt". The problem with this is that, for example, if I take a look at the generated "Interpolated_J_Inter.txt", the value for (0,0) differs notably.
Any ideas? Dear all
I am attaching a dataset, called "Points.txt", where the first and second columns represent the spatial coordinates along the x- and y-th directions, respectively, and the third column the value of a variable at each listed pair of points (x,y). I was wondering which could be a good way to increase the number of points mainly inside the hexagonal shape within the current listed points are restricted to:
I have tried the following:
pgon=nsidedpoly(6,’Center’,[0 0],’SideLength’,1);
%% Let’s rearrange the data associated to the interlayer isotropic exchange, Jinter
% Let’s load the preliminar data
Jinter=cell2mat(struct2cell(load(strcat(pwd,’Preliminar-DataJinter.mat’))));
% Let’s construct the unit vectors of the in-plane unit cell
x=unique(Jinter(:,1));
y=unique(Jinter(:,2));
a1_points=[max(x) 0];
a2_points=[-0.5 max(y)];
a1_modulus=sqrt(dot(a1_points,a1_points));
a2_modulus=sqrt(dot(a2_points,a2_points));
a1=a1_points./a1_modulus;
a2=a2_points./a2_modulus;
% Let’s construct the supercell for Jinter
diff_y=max(y)-min(y);
counter=0;
for dy=[-1 0 1]
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)++dy*[0 1]*diff_y)~=any(Jinter(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+dy*[0 1]*diff_y;
Jinter_extended(counter,3)=Jinter(i,3);
end
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
clear a1 a2 a1_modulus a2_modulus a1_points a2_points Jinter diff_y x y dy
% Let’s plot it
u17=figure(17)
scatter(Jinter_extended(:,1),Jinter_extended(:,2),[],Jinter_extended(:,3),’o’,’filled’);
colormap(gca,bluewhitered(256));
clim([min(Jinter_extended(:,3)) max(Jinter_extended(:,3))]);
clr17=colorbar;
box on;
pbaspect([1 6/4 1]);
clear u17 clr17
% Now, let’s interpolate data
x_extended=linspace(min(Jinter_extended(:,1)),max(Jinter_extended(:,1)));
y_extended=linspace(min(Jinter_extended(:,2)),max(Jinter_extended(:,2)));
Jinter_interpolated=RegularizeData3D(Jinter_extended(:,1),Jinter_extended(:,2),Jinter_extended(:,3),x_extended,y_extended,’interp’,’bicubic’,’smoothness’,1e-4);
x_interpolation=linspace(-1,1,201);
y_interpolation=linspace(-sqrt(3)/2,sqrt(3)/2,201);
[X,Y]=meshgrid(x_interpolation,y_interpolation);
interpolated_Jinter=interp2(x_extended,y_extended,Jinter_interpolated,X,Y,’cubic’);
clear X Y Jinter_interpolated x_extended y_extended Jinter_extended
% Let’s plot it
u18=figure(18)
uimagesc(x_interpolation,y_interpolation,interpolated_Jinter);
colormap(gca,bluewhitered(256));
% hold on
axis xy;
% plot(pgon);
clim([min(min(interpolated_Jinter)) max(max(interpolated_Jinter))]);
clr18=colorbar;
box on;
pbaspect([1 sqrt(3)/2 1]);
clear u18 clr18
% Now, let’s rearrange and save the data
x_intermediate=linspace(-100,100,201);
y_intermediate=linspace(-100,100,201);
counter=0;
for i=1:length(x_interpolation)
for j=1:length(y_interpolation)
counter=counter+1;
Jinter_save(counter,1)=x_intermediate(i);
Jinter_save(counter,2)=y_intermediate(j);
Jinter_save(counter,3)=interpolated_Jinter(i,j);
end
end
writematrix(Jinter_save,strcat(pwd,’Interpolated-DataInterpolated_J_Inter.txt’),’Delimiter’,’space’);
clear interpolated_Jinter Jinter_save x_interpolation y_interpolation counter i j x_intermediate y_intermediate
where the "Jinter.mat" is exactly the same dataset as in "Points.txt". The problem with this is that, for example, if I take a look at the generated "Interpolated_J_Inter.txt", the value for (0,0) differs notably.
Any ideas? interpolate two-dimensional data MATLAB Answers — New Questions
Simulink generated code optimization – CPU Load
Hi all,
I’m successfully generating code from the Simulink model. This code substitute manual one with the same function. Code is the integrated with the rest of the manual code, flashed to the HW and running. This substituting of the manual code part with the generated one increses the CPU Load. When I’m checking the Code generation setting, basic targets are RAM minimazing or Execution speed mazimazing. Non of these will directly reduce the CPU Load I suppose.
So I’d like to ask you, do you know what Advanced or Detailed Code generation Optimization setting can reduce the CPU Load? I’m attaching screenshots of the current setting.
And possibly follow up question – is there any metric which can estimate affect on the CPU Load without need of flashing the integrated code to the HW?
Thank you for your help in advance, have a nice day!
OldrichHi all,
I’m successfully generating code from the Simulink model. This code substitute manual one with the same function. Code is the integrated with the rest of the manual code, flashed to the HW and running. This substituting of the manual code part with the generated one increses the CPU Load. When I’m checking the Code generation setting, basic targets are RAM minimazing or Execution speed mazimazing. Non of these will directly reduce the CPU Load I suppose.
So I’d like to ask you, do you know what Advanced or Detailed Code generation Optimization setting can reduce the CPU Load? I’m attaching screenshots of the current setting.
And possibly follow up question – is there any metric which can estimate affect on the CPU Load without need of flashing the integrated code to the HW?
Thank you for your help in advance, have a nice day!
Oldrich Hi all,
I’m successfully generating code from the Simulink model. This code substitute manual one with the same function. Code is the integrated with the rest of the manual code, flashed to the HW and running. This substituting of the manual code part with the generated one increses the CPU Load. When I’m checking the Code generation setting, basic targets are RAM minimazing or Execution speed mazimazing. Non of these will directly reduce the CPU Load I suppose.
So I’d like to ask you, do you know what Advanced or Detailed Code generation Optimization setting can reduce the CPU Load? I’m attaching screenshots of the current setting.
And possibly follow up question – is there any metric which can estimate affect on the CPU Load without need of flashing the integrated code to the HW?
Thank you for your help in advance, have a nice day!
Oldrich embedded coder MATLAB Answers — New Questions