Tag Archives: matlab
How can I install specific products within the MATLAB Runtime to save space?
The MATLAB Runtime installer provided on the MathWorks Website is monolithic, offering no options for selective installation and requiring several gigabytes of space. Is it possible to create a custom installer for the MATLAB Runtime that includes only the components necessary for my compiled MATLAB application(s), resulting in a smaller installation size?The MATLAB Runtime installer provided on the MathWorks Website is monolithic, offering no options for selective installation and requiring several gigabytes of space. Is it possible to create a custom installer for the MATLAB Runtime that includes only the components necessary for my compiled MATLAB application(s), resulting in a smaller installation size? The MATLAB Runtime installer provided on the MathWorks Website is monolithic, offering no options for selective installation and requiring several gigabytes of space. Is it possible to create a custom installer for the MATLAB Runtime that includes only the components necessary for my compiled MATLAB application(s), resulting in a smaller installation size? mcr, monolithic, slim, installer, selective, space, efficient, requiredmcrproducts.txt, customize, custom MATLAB Answers — New Questions
How can I distribute my standalone application with a minimal MATLAB Runtime installation?
I’ve developed a MATLAB application and aim to compile it with MATLAB Compiler and then distribute it as compactly as possible. Is there a way to avoid installing the full MATLAB Runtime if my compiled application only requires a few specific toolboxes?I’ve developed a MATLAB application and aim to compile it with MATLAB Compiler and then distribute it as compactly as possible. Is there a way to avoid installing the full MATLAB Runtime if my compiled application only requires a few specific toolboxes? I’ve developed a MATLAB application and aim to compile it with MATLAB Compiler and then distribute it as compactly as possible. Is there a way to avoid installing the full MATLAB Runtime if my compiled application only requires a few specific toolboxes? requiredmcrproducts.txt, slim, matlab, runtime, reduced, partial, subset, monolithic, selective, installation, mcr, deploytool MATLAB Answers — New Questions
How can I generate C code for my MATLAB code that has a separate H and C file for each MATLAB function?
I have written several MATLAB functions for my application that call each other. These MATLAB functions are in separate files.
I would like to preserve this file structure when I generate C code, I want to generate one header and a source file for each MATLAB function.
How can I do this?I have written several MATLAB functions for my application that call each other. These MATLAB functions are in separate files.
I would like to preserve this file structure when I generate C code, I want to generate one header and a source file for each MATLAB function.
How can I do this? I have written several MATLAB functions for my application that call each other. These MATLAB functions are in separate files.
I would like to preserve this file structure when I generate C code, I want to generate one header and a source file for each MATLAB function.
How can I do this? c, embeddedcoder, filestructure MATLAB Answers — New Questions
Implementation of the analytical expression for the magnetic field of a circular current loop and interpretation/representation of the results
I want to analytically approximate the magnetic field of a few coil arrangements. For this purpose i found a very helpful paper: 20140002333.pdf (nasa.gov). On page 8 of the PDF document are the analytic expressions for the field components of the magnetic field in spherical coordinates:
This is my implementation:
function [B_r,B_theta] = magneticField_circularCoil(I,N,a,r,theta)
%MAGNETICFIELDCOMPONENTS Calculates the magnetic field components B_r and
%B_theta (spherical coordinates)
% B_r: B component in r direction
% B_theta: B component in theta direction
% I: current through conductor
% N: number of coil windings
% a: radius of the coil
% r: distance from the origin (spherical coordinates)
% theta: angle to z-axis (spherical coordinates) IN DEGREES
%
% Source for used analytic formula:
% https://ntrs.nasa.gov/api/citations/20140002333/downloads/20140002333.pdf
mu0 = 4.*pi.*1e-7;
alpha2 = a.^2 + r.^2 – 2.*a.*r.*sind(theta);
beta2 = a.^2 + r.^2 + 2.*a.*r.*sind(theta);
k2 = 1 – alpha2./beta2;
C = mu0 * I./pi;
[K_k2,E_k2] = ellipke(k2);
B_r = N.*(C.*a.^2.*cosd(theta))./(alpha2.*sqrt(beta2)) .* E_k2;
B_theta = N.*C./(2.*alpha2.*sqrt(beta2).*sind(theta)) .* ((r.^2+a.^2.*cosd(2.*theta)).*E_k2 – alpha2.*K_k2);
B_phi = 0;
end
To test the function, I wrote the following code:
%% Analytical calculation of the magnetic field of the Helmholtz coil arrangement %%
% Approximation: The coil diameter is neglected. All windings "in one
% place"
% approximation: The magnetic table top is assumed to act as a perfect
% magnetic "mirror" is assumed.
%
format compact;
% Radius of the Coil in meters:
a = 0.2;
% Current through Coil in amperes:
I = 5.0;
% Number of Coil windings:
N = 154; % source: datasheet Helmholtz coils
r_test = sqrt(0.2.^2+0.2.^2);
[B_r1,B_theta1] = magneticField_circularCoil(I,N,a,r_test,45.0)
[B_r2,B_theta2] = magneticField_circularCoil(I,N,a,r_test,135.0)
This leads to the following expected results (the magnitude of the resulting field is the same but it’s in different directions):
>> Magnetfeld_Helmholtzspule_analytisch
B_r1 =
5.2273e-04
B_theta1 =
-4.2355e-06
B_r2 =
-5.2273e-04
B_theta2 =
-4.2355e-06
Is my implementation of the field components correct?
And how could I represent the superimposed field of two (or more) coils? I would appreciate any ideas!I want to analytically approximate the magnetic field of a few coil arrangements. For this purpose i found a very helpful paper: 20140002333.pdf (nasa.gov). On page 8 of the PDF document are the analytic expressions for the field components of the magnetic field in spherical coordinates:
This is my implementation:
function [B_r,B_theta] = magneticField_circularCoil(I,N,a,r,theta)
%MAGNETICFIELDCOMPONENTS Calculates the magnetic field components B_r and
%B_theta (spherical coordinates)
% B_r: B component in r direction
% B_theta: B component in theta direction
% I: current through conductor
% N: number of coil windings
% a: radius of the coil
% r: distance from the origin (spherical coordinates)
% theta: angle to z-axis (spherical coordinates) IN DEGREES
%
% Source for used analytic formula:
% https://ntrs.nasa.gov/api/citations/20140002333/downloads/20140002333.pdf
mu0 = 4.*pi.*1e-7;
alpha2 = a.^2 + r.^2 – 2.*a.*r.*sind(theta);
beta2 = a.^2 + r.^2 + 2.*a.*r.*sind(theta);
k2 = 1 – alpha2./beta2;
C = mu0 * I./pi;
[K_k2,E_k2] = ellipke(k2);
B_r = N.*(C.*a.^2.*cosd(theta))./(alpha2.*sqrt(beta2)) .* E_k2;
B_theta = N.*C./(2.*alpha2.*sqrt(beta2).*sind(theta)) .* ((r.^2+a.^2.*cosd(2.*theta)).*E_k2 – alpha2.*K_k2);
B_phi = 0;
end
To test the function, I wrote the following code:
%% Analytical calculation of the magnetic field of the Helmholtz coil arrangement %%
% Approximation: The coil diameter is neglected. All windings "in one
% place"
% approximation: The magnetic table top is assumed to act as a perfect
% magnetic "mirror" is assumed.
%
format compact;
% Radius of the Coil in meters:
a = 0.2;
% Current through Coil in amperes:
I = 5.0;
% Number of Coil windings:
N = 154; % source: datasheet Helmholtz coils
r_test = sqrt(0.2.^2+0.2.^2);
[B_r1,B_theta1] = magneticField_circularCoil(I,N,a,r_test,45.0)
[B_r2,B_theta2] = magneticField_circularCoil(I,N,a,r_test,135.0)
This leads to the following expected results (the magnitude of the resulting field is the same but it’s in different directions):
>> Magnetfeld_Helmholtzspule_analytisch
B_r1 =
5.2273e-04
B_theta1 =
-4.2355e-06
B_r2 =
-5.2273e-04
B_theta2 =
-4.2355e-06
Is my implementation of the field components correct?
And how could I represent the superimposed field of two (or more) coils? I would appreciate any ideas! I want to analytically approximate the magnetic field of a few coil arrangements. For this purpose i found a very helpful paper: 20140002333.pdf (nasa.gov). On page 8 of the PDF document are the analytic expressions for the field components of the magnetic field in spherical coordinates:
This is my implementation:
function [B_r,B_theta] = magneticField_circularCoil(I,N,a,r,theta)
%MAGNETICFIELDCOMPONENTS Calculates the magnetic field components B_r and
%B_theta (spherical coordinates)
% B_r: B component in r direction
% B_theta: B component in theta direction
% I: current through conductor
% N: number of coil windings
% a: radius of the coil
% r: distance from the origin (spherical coordinates)
% theta: angle to z-axis (spherical coordinates) IN DEGREES
%
% Source for used analytic formula:
% https://ntrs.nasa.gov/api/citations/20140002333/downloads/20140002333.pdf
mu0 = 4.*pi.*1e-7;
alpha2 = a.^2 + r.^2 – 2.*a.*r.*sind(theta);
beta2 = a.^2 + r.^2 + 2.*a.*r.*sind(theta);
k2 = 1 – alpha2./beta2;
C = mu0 * I./pi;
[K_k2,E_k2] = ellipke(k2);
B_r = N.*(C.*a.^2.*cosd(theta))./(alpha2.*sqrt(beta2)) .* E_k2;
B_theta = N.*C./(2.*alpha2.*sqrt(beta2).*sind(theta)) .* ((r.^2+a.^2.*cosd(2.*theta)).*E_k2 – alpha2.*K_k2);
B_phi = 0;
end
To test the function, I wrote the following code:
%% Analytical calculation of the magnetic field of the Helmholtz coil arrangement %%
% Approximation: The coil diameter is neglected. All windings "in one
% place"
% approximation: The magnetic table top is assumed to act as a perfect
% magnetic "mirror" is assumed.
%
format compact;
% Radius of the Coil in meters:
a = 0.2;
% Current through Coil in amperes:
I = 5.0;
% Number of Coil windings:
N = 154; % source: datasheet Helmholtz coils
r_test = sqrt(0.2.^2+0.2.^2);
[B_r1,B_theta1] = magneticField_circularCoil(I,N,a,r_test,45.0)
[B_r2,B_theta2] = magneticField_circularCoil(I,N,a,r_test,135.0)
This leads to the following expected results (the magnitude of the resulting field is the same but it’s in different directions):
>> Magnetfeld_Helmholtzspule_analytisch
B_r1 =
5.2273e-04
B_theta1 =
-4.2355e-06
B_r2 =
-5.2273e-04
B_theta2 =
-4.2355e-06
Is my implementation of the field components correct?
And how could I represent the superimposed field of two (or more) coils? I would appreciate any ideas! electromagnetism, magnetic field, coil MATLAB Answers — New Questions
How to convert gyroscopic data and parameters for “factorIMU” usage?
I am using Factor Graph based workflow, as described in the following documentation:
https://www.mathworks.com/help/nav/ug/factor-graph-based-pedestrian-localization-imu-gps.html
How can I prepare my raw data from the IMU sensor for this workflow? Secondly, how do I determine and populate the various input variables to "factorIMU" object, such as "AccelerometerNoise", "GyroscopeNoise", "AccelerometerBiasNoise", "GyroscopeBiasNoise"?I am using Factor Graph based workflow, as described in the following documentation:
https://www.mathworks.com/help/nav/ug/factor-graph-based-pedestrian-localization-imu-gps.html
How can I prepare my raw data from the IMU sensor for this workflow? Secondly, how do I determine and populate the various input variables to "factorIMU" object, such as "AccelerometerNoise", "GyroscopeNoise", "AccelerometerBiasNoise", "GyroscopeBiasNoise"? I am using Factor Graph based workflow, as described in the following documentation:
https://www.mathworks.com/help/nav/ug/factor-graph-based-pedestrian-localization-imu-gps.html
How can I prepare my raw data from the IMU sensor for this workflow? Secondly, how do I determine and populate the various input variables to "factorIMU" object, such as "AccelerometerNoise", "GyroscopeNoise", "AccelerometerBiasNoise", "GyroscopeBiasNoise"? factorimu, imu, factorgraph, sensordatainterpretation MATLAB Answers — New Questions
How to fix this Error? __ No constructor ‘handle.listener’ with matching signature found.
I have been getting the following error:
No constructor ‘handle.listener’ with matching
signature found.
Error in ut_subplot>ut_createListeners (line
427)
handle.listener(axlisth,findprop(axlisth(1),’OuterPosition’),
…
Error in ut_subplot>ut_addAxesToGrid (line 464)
ut_createListeners(p,handle(list));
Error in ut_subplot (line 398)
ut_addAxesToGrid(ax,nrows,ncols,row,col,inset);
Error in meo_plot (line 43)
ut_subplot(1,2,1);
Error in meofis_optimize (line 198)
meo_plot(new_pop, meo);
Error in meofis_batch (line 103)
meofis_optimize();
I am using MATLAB 2019a. The code isn’t mine and is supposed to be from 2007. The code stops in the middle of drawing a graph in a gui.
The whole line where is stops — including line 427 — is:
list = […
handle.listener(axlisth,findprop(axlisth(1),’OuterPosition’), …
‘PropertyPostSet’,@ut_axesMoved); % <<—- PROBLEM LINE
handle.listener(axlisth,findprop(axlisth(1),’ActivePositionProperty’), …
‘PropertyPreSet’,@ut_axesMoved);
handle.listener(axlisth,findprop(axlisth(1),’Parent’), …
‘PropertyPreSet’,@ut_axesMoved);
handle.listener(axlisth,’AxisInvalidEvent’,{@subplotlayoutInvalid,p});
handle.listener(handle(fig),’FigureUpdateEvent’,{@subplotlayout,p})];
I did try the brute force solution of just commenting out the problem line, but the same type of error just showed up with the line right after it. Any help would be most welcome.
I have found this Ask/Answer here, but either I ddin’t understant it or it isn’t quite the same problem; I tried changing the names of the functions I was using in case they were the same as some that MATLAB uses, but I still got the same error.
https://www.mathworks.com/matlabcentral/answers/165049-subplot-error-no-constructor-handle-listener-with-matching-signature-found-matlab-2014b?s_tid=srchtitle
Sadly, this question for a very similar error didn’t get a reply:
https://www.mathworks.com/matlabcentral/answers/1723870-no-constructor-handle-listener-with-matching-signature-found?s_tid=srchtitleI have been getting the following error:
No constructor ‘handle.listener’ with matching
signature found.
Error in ut_subplot>ut_createListeners (line
427)
handle.listener(axlisth,findprop(axlisth(1),’OuterPosition’),
…
Error in ut_subplot>ut_addAxesToGrid (line 464)
ut_createListeners(p,handle(list));
Error in ut_subplot (line 398)
ut_addAxesToGrid(ax,nrows,ncols,row,col,inset);
Error in meo_plot (line 43)
ut_subplot(1,2,1);
Error in meofis_optimize (line 198)
meo_plot(new_pop, meo);
Error in meofis_batch (line 103)
meofis_optimize();
I am using MATLAB 2019a. The code isn’t mine and is supposed to be from 2007. The code stops in the middle of drawing a graph in a gui.
The whole line where is stops — including line 427 — is:
list = […
handle.listener(axlisth,findprop(axlisth(1),’OuterPosition’), …
‘PropertyPostSet’,@ut_axesMoved); % <<—- PROBLEM LINE
handle.listener(axlisth,findprop(axlisth(1),’ActivePositionProperty’), …
‘PropertyPreSet’,@ut_axesMoved);
handle.listener(axlisth,findprop(axlisth(1),’Parent’), …
‘PropertyPreSet’,@ut_axesMoved);
handle.listener(axlisth,’AxisInvalidEvent’,{@subplotlayoutInvalid,p});
handle.listener(handle(fig),’FigureUpdateEvent’,{@subplotlayout,p})];
I did try the brute force solution of just commenting out the problem line, but the same type of error just showed up with the line right after it. Any help would be most welcome.
I have found this Ask/Answer here, but either I ddin’t understant it or it isn’t quite the same problem; I tried changing the names of the functions I was using in case they were the same as some that MATLAB uses, but I still got the same error.
https://www.mathworks.com/matlabcentral/answers/165049-subplot-error-no-constructor-handle-listener-with-matching-signature-found-matlab-2014b?s_tid=srchtitle
Sadly, this question for a very similar error didn’t get a reply:
https://www.mathworks.com/matlabcentral/answers/1723870-no-constructor-handle-listener-with-matching-signature-found?s_tid=srchtitle I have been getting the following error:
No constructor ‘handle.listener’ with matching
signature found.
Error in ut_subplot>ut_createListeners (line
427)
handle.listener(axlisth,findprop(axlisth(1),’OuterPosition’),
…
Error in ut_subplot>ut_addAxesToGrid (line 464)
ut_createListeners(p,handle(list));
Error in ut_subplot (line 398)
ut_addAxesToGrid(ax,nrows,ncols,row,col,inset);
Error in meo_plot (line 43)
ut_subplot(1,2,1);
Error in meofis_optimize (line 198)
meo_plot(new_pop, meo);
Error in meofis_batch (line 103)
meofis_optimize();
I am using MATLAB 2019a. The code isn’t mine and is supposed to be from 2007. The code stops in the middle of drawing a graph in a gui.
The whole line where is stops — including line 427 — is:
list = […
handle.listener(axlisth,findprop(axlisth(1),’OuterPosition’), …
‘PropertyPostSet’,@ut_axesMoved); % <<—- PROBLEM LINE
handle.listener(axlisth,findprop(axlisth(1),’ActivePositionProperty’), …
‘PropertyPreSet’,@ut_axesMoved);
handle.listener(axlisth,findprop(axlisth(1),’Parent’), …
‘PropertyPreSet’,@ut_axesMoved);
handle.listener(axlisth,’AxisInvalidEvent’,{@subplotlayoutInvalid,p});
handle.listener(handle(fig),’FigureUpdateEvent’,{@subplotlayout,p})];
I did try the brute force solution of just commenting out the problem line, but the same type of error just showed up with the line right after it. Any help would be most welcome.
I have found this Ask/Answer here, but either I ddin’t understant it or it isn’t quite the same problem; I tried changing the names of the functions I was using in case they were the same as some that MATLAB uses, but I still got the same error.
https://www.mathworks.com/matlabcentral/answers/165049-subplot-error-no-constructor-handle-listener-with-matching-signature-found-matlab-2014b?s_tid=srchtitle
Sadly, this question for a very similar error didn’t get a reply:
https://www.mathworks.com/matlabcentral/answers/1723870-no-constructor-handle-listener-with-matching-signature-found?s_tid=srchtitle constructor, handle.listener, signature, matching signature MATLAB Answers — New Questions
convert gifti to nifti files
Dear all,
I’m using CAT12 to mesure cortical thickness : as results i have gifti files (.gii) but i don’t know how to convert them in to nifti files: is anyone has a Matlab script for this?
Thank you so much,Dear all,
I’m using CAT12 to mesure cortical thickness : as results i have gifti files (.gii) but i don’t know how to convert them in to nifti files: is anyone has a Matlab script for this?
Thank you so much, Dear all,
I’m using CAT12 to mesure cortical thickness : as results i have gifti files (.gii) but i don’t know how to convert them in to nifti files: is anyone has a Matlab script for this?
Thank you so much, gifti nifti MATLAB Answers — New Questions
How do I print a % character into a file
I am creating an app in App Designer, creating an output file that will be an .m file for another user to run later.
I’d like to put a comment header at the start of this file but I can’t double excape the % character
app.SessionFile = fopen(app.SessionFileName,’at’);
str = sprintf("%% Parameters: %c%u…",v1,v2…); % Put required string into str – works
str is now "% Paramters: …." but it won’t go out to the file with
fprintf(app.SessionFile,str); % Nothing gets printed, comment gets stripped out!
(0 chars printed)
Also not working
str = sprintf("%%% Parameters:
str = sprintf(" %% Parameters:
Seems like if I have a string I want to put in a text file MatLab shouldn’t mess with it.
Also: is ‘at’ the same as ‘wt’ ? seems like it always appends anyway with fprint.I am creating an app in App Designer, creating an output file that will be an .m file for another user to run later.
I’d like to put a comment header at the start of this file but I can’t double excape the % character
app.SessionFile = fopen(app.SessionFileName,’at’);
str = sprintf("%% Parameters: %c%u…",v1,v2…); % Put required string into str – works
str is now "% Paramters: …." but it won’t go out to the file with
fprintf(app.SessionFile,str); % Nothing gets printed, comment gets stripped out!
(0 chars printed)
Also not working
str = sprintf("%%% Parameters:
str = sprintf(" %% Parameters:
Seems like if I have a string I want to put in a text file MatLab shouldn’t mess with it.
Also: is ‘at’ the same as ‘wt’ ? seems like it always appends anyway with fprint. I am creating an app in App Designer, creating an output file that will be an .m file for another user to run later.
I’d like to put a comment header at the start of this file but I can’t double excape the % character
app.SessionFile = fopen(app.SessionFileName,’at’);
str = sprintf("%% Parameters: %c%u…",v1,v2…); % Put required string into str – works
str is now "% Paramters: …." but it won’t go out to the file with
fprintf(app.SessionFile,str); % Nothing gets printed, comment gets stripped out!
(0 chars printed)
Also not working
str = sprintf("%%% Parameters:
str = sprintf(" %% Parameters:
Seems like if I have a string I want to put in a text file MatLab shouldn’t mess with it.
Also: is ‘at’ the same as ‘wt’ ? seems like it always appends anyway with fprint. printing % to a file %% not working MATLAB Answers — New Questions
How to fix error in matlab code for the assignment of path?
I am using following lines of matlab code;
baseSNAP = "C:Program Filesesa-snapbingpt.exe";
cmd = [baseSNAP, aoFlag, out, oType, granule];
system(cmd);
it is giving the following error
Unrecognized function or variable ‘baseSNAP’.
I request to please suggest me how to fix this error.
Kuldeep TomarI am using following lines of matlab code;
baseSNAP = "C:Program Filesesa-snapbingpt.exe";
cmd = [baseSNAP, aoFlag, out, oType, granule];
system(cmd);
it is giving the following error
Unrecognized function or variable ‘baseSNAP’.
I request to please suggest me how to fix this error.
Kuldeep Tomar I am using following lines of matlab code;
baseSNAP = "C:Program Filesesa-snapbingpt.exe";
cmd = [baseSNAP, aoFlag, out, oType, granule];
system(cmd);
it is giving the following error
Unrecognized function or variable ‘baseSNAP’.
I request to please suggest me how to fix this error.
Kuldeep Tomar how to fix error for the assignment of path? MATLAB Answers — New Questions
How can I use MATLAB functions to generate a Simscape Model?
I want to generate a Simscape model using a MATLAB script because it will cut down on my work time significantly if I can generate it procedurally. I have been able to generate a Simulink model using commands like ‘add_block’, ‘add_line’, and ‘set_param’, but am having trouble generating a Simscape model the same way. How might I go about generating a Simscape model this way?I want to generate a Simscape model using a MATLAB script because it will cut down on my work time significantly if I can generate it procedurally. I have been able to generate a Simulink model using commands like ‘add_block’, ‘add_line’, and ‘set_param’, but am having trouble generating a Simscape model the same way. How might I go about generating a Simscape model this way? I want to generate a Simscape model using a MATLAB script because it will cut down on my work time significantly if I can generate it procedurally. I have been able to generate a Simulink model using commands like ‘add_block’, ‘add_line’, and ‘set_param’, but am having trouble generating a Simscape model the same way. How might I go about generating a Simscape model this way? programmatic, simscape, electrical, add_line, add_block, set_param MATLAB Answers — New Questions
Why am I unable to fit the data in the curve fitter app using the “Select data” button in MATLAB R2023b on MacOS?
I am trying to fit the data into the curve fitter app. I am unable to select the data using "Select data" button of the curve fitter app for X-coordinate, Y-coordinate and Z-coordinate data.
How can I get the curve fitter app to fit this data using the "Select data" button in MATLAB R2023b on MacOS?I am trying to fit the data into the curve fitter app. I am unable to select the data using "Select data" button of the curve fitter app for X-coordinate, Y-coordinate and Z-coordinate data.
How can I get the curve fitter app to fit this data using the "Select data" button in MATLAB R2023b on MacOS? I am trying to fit the data into the curve fitter app. I am unable to select the data using "Select data" button of the curve fitter app for X-coordinate, Y-coordinate and Z-coordinate data.
How can I get the curve fitter app to fit this data using the "Select data" button in MATLAB R2023b on MacOS? nan, curvefitter, loaddata, selectdata MATLAB Answers — New Questions
Why is there a difference between the elements of arrays created by the colon operator with the same step size?
If I create two arrays as follows and compare them, I get the following:
>> scan_period = 0.12; beam_param = 13;
>> dt = scan_period/beam_param;
>> TIME = 0.2189;
>> T = 0:dt:TIME;
>> legTime=0:dt:scan_period;
>> legTime – T(1:14)
ans =
1.0e-16 *
0 0 0 0 0 0 0 0.1388 0 0 0.1388 0.1388 0 0.1388
Why is there a difference between the elements of both arrays when they were created with the same step size?If I create two arrays as follows and compare them, I get the following:
>> scan_period = 0.12; beam_param = 13;
>> dt = scan_period/beam_param;
>> TIME = 0.2189;
>> T = 0:dt:TIME;
>> legTime=0:dt:scan_period;
>> legTime – T(1:14)
ans =
1.0e-16 *
0 0 0 0 0 0 0 0.1388 0 0 0.1388 0.1388 0 0.1388
Why is there a difference between the elements of both arrays when they were created with the same step size? If I create two arrays as follows and compare them, I get the following:
>> scan_period = 0.12; beam_param = 13;
>> dt = scan_period/beam_param;
>> TIME = 0.2189;
>> T = 0:dt:TIME;
>> legTime=0:dt:scan_period;
>> legTime – T(1:14)
ans =
1.0e-16 *
0 0 0 0 0 0 0 0.1388 0 0 0.1388 0.1388 0 0.1388
Why is there a difference between the elements of both arrays when they were created with the same step size? eps, floating-point, accuracy, colon MATLAB Answers — New Questions
How can I import “Pulse-based” or “Frame-based” data into Simulink models?
I have two models and I would like to feed the output of one model, "SourceModel", to the input of the second model, "DestinationModel".
In "SourceModel", I have a "Linear FM Waveform" block with the "Output Signal Format" set to "Pulses". I break that complex output into the real and imaginary portions, save the real portion into a MAT file called "Model1Out.mat", and then use a "To File" block with the "Save format" as "Array", as shown below:
In my second model, "DestinationModel", I would like to import the data saved in "Model1Out.mat" with a "From File" block, but I keep getting the following error:
"Invalid workspace variable specified as workspace input in ‘DestinationModel/From File’. Time values must be non decreasing".
I have tried loading the variable into the workspace to ensure the time values of the frames (first row of the matrix) are always increasing, and they are. I see the same error when I load the data into the workspace and use a "From Workspace" block. How can I get around this error?I have two models and I would like to feed the output of one model, "SourceModel", to the input of the second model, "DestinationModel".
In "SourceModel", I have a "Linear FM Waveform" block with the "Output Signal Format" set to "Pulses". I break that complex output into the real and imaginary portions, save the real portion into a MAT file called "Model1Out.mat", and then use a "To File" block with the "Save format" as "Array", as shown below:
In my second model, "DestinationModel", I would like to import the data saved in "Model1Out.mat" with a "From File" block, but I keep getting the following error:
"Invalid workspace variable specified as workspace input in ‘DestinationModel/From File’. Time values must be non decreasing".
I have tried loading the variable into the workspace to ensure the time values of the frames (first row of the matrix) are always increasing, and they are. I see the same error when I load the data into the workspace and use a "From Workspace" block. How can I get around this error? I have two models and I would like to feed the output of one model, "SourceModel", to the input of the second model, "DestinationModel".
In "SourceModel", I have a "Linear FM Waveform" block with the "Output Signal Format" set to "Pulses". I break that complex output into the real and imaginary portions, save the real portion into a MAT file called "Model1Out.mat", and then use a "To File" block with the "Save format" as "Array", as shown below:
In my second model, "DestinationModel", I would like to import the data saved in "Model1Out.mat" with a "From File" block, but I keep getting the following error:
"Invalid workspace variable specified as workspace input in ‘DestinationModel/From File’. Time values must be non decreasing".
I have tried loading the variable into the workspace to ensure the time values of the frames (first row of the matrix) are always increasing, and they are. I see the same error when I load the data into the workspace and use a "From Workspace" block. How can I get around this error? frame-based, pulse-based, to, workspace, file, from, linear, fm, waveform MATLAB Answers — New Questions
Why do I receive the error “The procedure entry point GetCurrentThreadStackLimits could not be located in the dynamic link library KERNEL32.dll.” when attempting to run the MathWorks Product Installer?
Why do I receive the error "The procedure entry point GetCurrentThreadStackLimits could not be located in the dynamic link library KERNEL32.dll." when attempting to run the MathWorks Product Installer?Why do I receive the error "The procedure entry point GetCurrentThreadStackLimits could not be located in the dynamic link library KERNEL32.dll." when attempting to run the MathWorks Product Installer? Why do I receive the error "The procedure entry point GetCurrentThreadStackLimits could not be located in the dynamic link library KERNEL32.dll." when attempting to run the MathWorks Product Installer? MATLAB Answers — New Questions
Valid Coin Mask True Pixels Error Outside or Beyond the Actual Mask Error
imread("testCoinImage3.png");
[testcoinMask,MaskedtestCoin] = segmentCoinFace(testCoinImage);
se = strel("disk", 4, 0);
testcoinMask = imfill(testcoinMask, "holes");
testcoinMask = imerode(testcoinMask, se);
imgFilt = imgaussfilt(MaskedtestCoin, 1, ‘Padding’, ‘circular’, ‘FilterDomain’, ‘frequency’, ‘FilterSize’, 3);
faceEdgeMask = edge(imgFilt, "sobel", 0.09, "both");
faceEdgeMask(~testcoinMask) = false;
seFE = strel("disk",75,0);
fEdgeMask = imfill(faceEdgeMask, "holes");
BW2 = imdilate(fEdgeMask,seFE);
validCoinMask = BW2 & testcoinMask;
se2 = strel(‘disk’,75,0);
validcoinMask = imdilate(validCoinMask, se2);
coinProps = regionprops("table", validCoinMask, ‘Area’, ‘Perimeter’);
areas = table2array(coinProps(:, ‘Area’));
range = [min(areas ) max(areas)];
validCoinMask = bwareafilt(validCoinMask, range);
imshow(validCoinMask)
function [BW,maskedImage] = segmentCoinFace(X)
%segmentImage Segment image using auto-generated code from Image Segmenter app
% [BW,MASKEDIMAGE] = segmentImage(X) segments image X using auto-generated
% code from the Image Segmenter app. The final segmentation is returned in
% BW, and a masked image is returned in MASKEDIMAGE.
% Auto-generated by imageSegmenter app on 08-Jul-2023
%—————————————————-
% Adjust data to span data range.
X = imadjust(X);
% Threshold image with global threshold
BW = imbinarize(im2gray(X));
% Open mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imopen(BW, se);testCoinImage = imread("testCoinImage3.png");
[testcoinMask,MaskedtestCoin] = segmentCoin(testCoinImage);
% Shrink the coin mask.
se = strel(‘disk’, 3, 0);
testcoinMask = imfill(testcoinMask, ‘holes’); % Fill any holes in it.
testcoinMask = imerode(testcoinMask, se); % Shrink by 3 layers of pixels.
% Find edges using original poster’s code.
imgFilt = imgaussfilt(MaskedtestCoin,0.7,…
Padding="circular",FilterDomain="frequency",FilterSize=3);
faceEdgeMask = edge(imgFilt,"sobel",0.1,"both");
% Erase outside the shrunken coin mask to get rid of outer boundary.
faceEdgeMask(~testcoinMask) = false;
imshow(faceEdgeMask);
function [BW,maskedImage] = segmentCoin(X)
%segmentImage Segment image using auto-generated code from Image Segmenter app
% [BW,MASKEDIMAGE] = segmentImage(X) segments image X using auto-generated
% code from the Image Segmenter app. The final segmentation is returned in
% BW, and a masked image is returned in MASKEDIMAGE.
% Auto-generated by imageSegmenter app on 08-Jul-2023
%—————————————————-
% Adjust data to span data range.
X = imadjust(X);
% Threshold image with global threshold
BW = imbinarize(im2gray(X));
% Open mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imopen(BW, se);
% Close mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imclose(BW, se);
% Fill holes
BW = imfill(BW, ‘holes’);
% Invert mask
BW = imcomplement(BW);
% Invert mask
BW = imcomplement(BW);
% Create masked image.
maskedImage = X;
maskedImage(~BW) = 0;
end
% Close mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imclose(BW, se);
% Fill holes
BW = imfill(BW, ‘holes’);
% Invert mask
BW = imcomplement(BW);
% Invert mask
BW = imcomplement(BW);
% Create masked image.
maskedImage = X;
maskedImage(~BW) = 0;
end
in the se variable for structuring element , when I change the value to 4 it shows "Your valid coin mask has one or more true pixels outside valid coins," and when I change the se value to another value later on, it would show that it isn’t covering all true valid coins . Please if you can help, I’ve been stuck on this since the past 3 days and I’m getting quite frustrated grrr. Thanks :)imread("testCoinImage3.png");
[testcoinMask,MaskedtestCoin] = segmentCoinFace(testCoinImage);
se = strel("disk", 4, 0);
testcoinMask = imfill(testcoinMask, "holes");
testcoinMask = imerode(testcoinMask, se);
imgFilt = imgaussfilt(MaskedtestCoin, 1, ‘Padding’, ‘circular’, ‘FilterDomain’, ‘frequency’, ‘FilterSize’, 3);
faceEdgeMask = edge(imgFilt, "sobel", 0.09, "both");
faceEdgeMask(~testcoinMask) = false;
seFE = strel("disk",75,0);
fEdgeMask = imfill(faceEdgeMask, "holes");
BW2 = imdilate(fEdgeMask,seFE);
validCoinMask = BW2 & testcoinMask;
se2 = strel(‘disk’,75,0);
validcoinMask = imdilate(validCoinMask, se2);
coinProps = regionprops("table", validCoinMask, ‘Area’, ‘Perimeter’);
areas = table2array(coinProps(:, ‘Area’));
range = [min(areas ) max(areas)];
validCoinMask = bwareafilt(validCoinMask, range);
imshow(validCoinMask)
function [BW,maskedImage] = segmentCoinFace(X)
%segmentImage Segment image using auto-generated code from Image Segmenter app
% [BW,MASKEDIMAGE] = segmentImage(X) segments image X using auto-generated
% code from the Image Segmenter app. The final segmentation is returned in
% BW, and a masked image is returned in MASKEDIMAGE.
% Auto-generated by imageSegmenter app on 08-Jul-2023
%—————————————————-
% Adjust data to span data range.
X = imadjust(X);
% Threshold image with global threshold
BW = imbinarize(im2gray(X));
% Open mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imopen(BW, se);testCoinImage = imread("testCoinImage3.png");
[testcoinMask,MaskedtestCoin] = segmentCoin(testCoinImage);
% Shrink the coin mask.
se = strel(‘disk’, 3, 0);
testcoinMask = imfill(testcoinMask, ‘holes’); % Fill any holes in it.
testcoinMask = imerode(testcoinMask, se); % Shrink by 3 layers of pixels.
% Find edges using original poster’s code.
imgFilt = imgaussfilt(MaskedtestCoin,0.7,…
Padding="circular",FilterDomain="frequency",FilterSize=3);
faceEdgeMask = edge(imgFilt,"sobel",0.1,"both");
% Erase outside the shrunken coin mask to get rid of outer boundary.
faceEdgeMask(~testcoinMask) = false;
imshow(faceEdgeMask);
function [BW,maskedImage] = segmentCoin(X)
%segmentImage Segment image using auto-generated code from Image Segmenter app
% [BW,MASKEDIMAGE] = segmentImage(X) segments image X using auto-generated
% code from the Image Segmenter app. The final segmentation is returned in
% BW, and a masked image is returned in MASKEDIMAGE.
% Auto-generated by imageSegmenter app on 08-Jul-2023
%—————————————————-
% Adjust data to span data range.
X = imadjust(X);
% Threshold image with global threshold
BW = imbinarize(im2gray(X));
% Open mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imopen(BW, se);
% Close mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imclose(BW, se);
% Fill holes
BW = imfill(BW, ‘holes’);
% Invert mask
BW = imcomplement(BW);
% Invert mask
BW = imcomplement(BW);
% Create masked image.
maskedImage = X;
maskedImage(~BW) = 0;
end
% Close mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imclose(BW, se);
% Fill holes
BW = imfill(BW, ‘holes’);
% Invert mask
BW = imcomplement(BW);
% Invert mask
BW = imcomplement(BW);
% Create masked image.
maskedImage = X;
maskedImage(~BW) = 0;
end
in the se variable for structuring element , when I change the value to 4 it shows "Your valid coin mask has one or more true pixels outside valid coins," and when I change the se value to another value later on, it would show that it isn’t covering all true valid coins . Please if you can help, I’ve been stuck on this since the past 3 days and I’m getting quite frustrated grrr. Thanks 🙂 imread("testCoinImage3.png");
[testcoinMask,MaskedtestCoin] = segmentCoinFace(testCoinImage);
se = strel("disk", 4, 0);
testcoinMask = imfill(testcoinMask, "holes");
testcoinMask = imerode(testcoinMask, se);
imgFilt = imgaussfilt(MaskedtestCoin, 1, ‘Padding’, ‘circular’, ‘FilterDomain’, ‘frequency’, ‘FilterSize’, 3);
faceEdgeMask = edge(imgFilt, "sobel", 0.09, "both");
faceEdgeMask(~testcoinMask) = false;
seFE = strel("disk",75,0);
fEdgeMask = imfill(faceEdgeMask, "holes");
BW2 = imdilate(fEdgeMask,seFE);
validCoinMask = BW2 & testcoinMask;
se2 = strel(‘disk’,75,0);
validcoinMask = imdilate(validCoinMask, se2);
coinProps = regionprops("table", validCoinMask, ‘Area’, ‘Perimeter’);
areas = table2array(coinProps(:, ‘Area’));
range = [min(areas ) max(areas)];
validCoinMask = bwareafilt(validCoinMask, range);
imshow(validCoinMask)
function [BW,maskedImage] = segmentCoinFace(X)
%segmentImage Segment image using auto-generated code from Image Segmenter app
% [BW,MASKEDIMAGE] = segmentImage(X) segments image X using auto-generated
% code from the Image Segmenter app. The final segmentation is returned in
% BW, and a masked image is returned in MASKEDIMAGE.
% Auto-generated by imageSegmenter app on 08-Jul-2023
%—————————————————-
% Adjust data to span data range.
X = imadjust(X);
% Threshold image with global threshold
BW = imbinarize(im2gray(X));
% Open mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imopen(BW, se);testCoinImage = imread("testCoinImage3.png");
[testcoinMask,MaskedtestCoin] = segmentCoin(testCoinImage);
% Shrink the coin mask.
se = strel(‘disk’, 3, 0);
testcoinMask = imfill(testcoinMask, ‘holes’); % Fill any holes in it.
testcoinMask = imerode(testcoinMask, se); % Shrink by 3 layers of pixels.
% Find edges using original poster’s code.
imgFilt = imgaussfilt(MaskedtestCoin,0.7,…
Padding="circular",FilterDomain="frequency",FilterSize=3);
faceEdgeMask = edge(imgFilt,"sobel",0.1,"both");
% Erase outside the shrunken coin mask to get rid of outer boundary.
faceEdgeMask(~testcoinMask) = false;
imshow(faceEdgeMask);
function [BW,maskedImage] = segmentCoin(X)
%segmentImage Segment image using auto-generated code from Image Segmenter app
% [BW,MASKEDIMAGE] = segmentImage(X) segments image X using auto-generated
% code from the Image Segmenter app. The final segmentation is returned in
% BW, and a masked image is returned in MASKEDIMAGE.
% Auto-generated by imageSegmenter app on 08-Jul-2023
%—————————————————-
% Adjust data to span data range.
X = imadjust(X);
% Threshold image with global threshold
BW = imbinarize(im2gray(X));
% Open mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imopen(BW, se);
% Close mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imclose(BW, se);
% Fill holes
BW = imfill(BW, ‘holes’);
% Invert mask
BW = imcomplement(BW);
% Invert mask
BW = imcomplement(BW);
% Create masked image.
maskedImage = X;
maskedImage(~BW) = 0;
end
% Close mask with default
radius = 2;
decomposition = 0;
se = strel(‘disk’, radius, decomposition);
BW = imclose(BW, se);
% Fill holes
BW = imfill(BW, ‘holes’);
% Invert mask
BW = imcomplement(BW);
% Invert mask
BW = imcomplement(BW);
% Create masked image.
maskedImage = X;
maskedImage(~BW) = 0;
end
in the se variable for structuring element , when I change the value to 4 it shows "Your valid coin mask has one or more true pixels outside valid coins," and when I change the se value to another value later on, it would show that it isn’t covering all true valid coins . Please if you can help, I’ve been stuck on this since the past 3 days and I’m getting quite frustrated grrr. Thanks 🙂 image segmentation MATLAB Answers — New Questions
Increase temporal granularity in simulink
Hello, I have a simulink model based on the spacecraft dynamics example here:
https://www.mathworks.com/help/aeroblks/analyzing-spacecraft-attitude-profiles-with-satellite-scenario.html#SpacecraftDynamicsCustomAttitudeExample-1
that by default outputs the satellite position at intervals of roughly 10s when not pointing at specific targets (i.e. is in a "point at Nadir" state).
Is it possible to increase the temporal granularity across the whole orbit, in order to have for example a largest time step of 0.5s, even when pointing at Nadir?
Thank youHello, I have a simulink model based on the spacecraft dynamics example here:
https://www.mathworks.com/help/aeroblks/analyzing-spacecraft-attitude-profiles-with-satellite-scenario.html#SpacecraftDynamicsCustomAttitudeExample-1
that by default outputs the satellite position at intervals of roughly 10s when not pointing at specific targets (i.e. is in a "point at Nadir" state).
Is it possible to increase the temporal granularity across the whole orbit, in order to have for example a largest time step of 0.5s, even when pointing at Nadir?
Thank you Hello, I have a simulink model based on the spacecraft dynamics example here:
https://www.mathworks.com/help/aeroblks/analyzing-spacecraft-attitude-profiles-with-satellite-scenario.html#SpacecraftDynamicsCustomAttitudeExample-1
that by default outputs the satellite position at intervals of roughly 10s when not pointing at specific targets (i.e. is in a "point at Nadir" state).
Is it possible to increase the temporal granularity across the whole orbit, in order to have for example a largest time step of 0.5s, even when pointing at Nadir?
Thank you time granularity, satellite simulation MATLAB Answers — New Questions
Very large output numbers
I have a code which gives me the output of a transfer function with giant values, but I know that they can be reduced to get something smaller but I don’t know how, this would be an example of the output:
(6982830709666455*Kc*s)/140737488355328 or (6383029463564235*s^2)/2251799813685248I have a code which gives me the output of a transfer function with giant values, but I know that they can be reduced to get something smaller but I don’t know how, this would be an example of the output:
(6982830709666455*Kc*s)/140737488355328 or (6383029463564235*s^2)/2251799813685248 I have a code which gives me the output of a transfer function with giant values, but I know that they can be reduced to get something smaller but I don’t know how, this would be an example of the output:
(6982830709666455*Kc*s)/140737488355328 or (6383029463564235*s^2)/2251799813685248 solve, simplify, short MATLAB Answers — New Questions
How do I create a timetable from a file that contains several data columns with associated time columns?
I’ve got files which contain data multiple from multiple sensors. Each sensor has it’s own timestamp. Not all sensors have the same number of values.
Currently I’m splitting the file into several timetables. Then I’ll merge and synchronize the timetables and finally fill the missing values.
Is there a better way to do this, since the original files contain several hundred thousand lines for 50-60 signals?
txtArray= {‘Sig1_Time’ ‘Sig1_Value’ ‘Signal2_Time’ ‘Sig2_Value’ ‘Sig3_Time’ ‘Sig3_Value’;
‘4/28/2020 6:41:56.555 PM’ ‘92.1822814’ ‘4/28/2020 6:41:56.545 PM’ ‘21.2642456’ ‘4/28/2020 6:40:56.545 PM’ ‘1.26’;
‘4/28/2020 6:42:06.655 PM’ ‘92.2822814’ ‘4/28/2020 6:42:06.645 PM’ ‘22.3538671’ ‘4/28/2020 6:50:06.645 PM’ ‘2.35’;
‘4/28/2020 6:42:07.665 PM’ ‘92.1922814’ ‘4/28/2020 6:42:07.655 PM’ ‘22.2642456’ ” ”;
” ” ‘4/28/2020 6:42:08.665 PM’ ‘23.2822436’ ” ”;
” ” ‘4/28/2020 6:42:20.786 PM’ ‘22.2642456’ ” ”;
};
% find columns with timestamps
TimeCols = contains([txtArray(1,:)],’Time’,’IgnoreCase’,true);
% convert times to numerical values
times = datetime([txtArray(2:end,TimeCols)],’InputFormat’,’M/d/yyyy h:m:ss.SSS a’);
NoVars = sum(~TimeCols);
for j=1:NoVars
% create time column in TimeTable
TC = times(:,j);
% create data column in TimeTable
DC = cellfun(@(s) str2double(s),txtArray(:,2*j));
% merge arrays into Timetable, remove invalied (NaT) times
TT(j).tt = array2timetable(DC(~isnat(TC)),’RowTimes’,TC(~isnat(TC)));
end
% merge timetables
for j=1:NoVars
if ~issorted(TT(j).tt);
TT(j).tt=sortrows(TT(j).tt);
end
if j>1
if j==2
Ttable = TT(j-1).tt;
end
% synchronize removes dublicate times
Ttable = synchronize(Ttable,TT(j).tt); % https://mathworks.com/help/matlab/ref/timetable.synchronize.html
Ttable = fillmissing(Ttable,’previous’); % https://mathworks.com/help/matlab/ref/fillmissing.html
end
end
% fill missing values for the first lines which may still be empty
Ttable = fillmissing(Ttable,’next’);
% rename properties
Ttable.Properties.VariableNames = {‘Var1′,’Var2′,’Var3’};I’ve got files which contain data multiple from multiple sensors. Each sensor has it’s own timestamp. Not all sensors have the same number of values.
Currently I’m splitting the file into several timetables. Then I’ll merge and synchronize the timetables and finally fill the missing values.
Is there a better way to do this, since the original files contain several hundred thousand lines for 50-60 signals?
txtArray= {‘Sig1_Time’ ‘Sig1_Value’ ‘Signal2_Time’ ‘Sig2_Value’ ‘Sig3_Time’ ‘Sig3_Value’;
‘4/28/2020 6:41:56.555 PM’ ‘92.1822814’ ‘4/28/2020 6:41:56.545 PM’ ‘21.2642456’ ‘4/28/2020 6:40:56.545 PM’ ‘1.26’;
‘4/28/2020 6:42:06.655 PM’ ‘92.2822814’ ‘4/28/2020 6:42:06.645 PM’ ‘22.3538671’ ‘4/28/2020 6:50:06.645 PM’ ‘2.35’;
‘4/28/2020 6:42:07.665 PM’ ‘92.1922814’ ‘4/28/2020 6:42:07.655 PM’ ‘22.2642456’ ” ”;
” ” ‘4/28/2020 6:42:08.665 PM’ ‘23.2822436’ ” ”;
” ” ‘4/28/2020 6:42:20.786 PM’ ‘22.2642456’ ” ”;
};
% find columns with timestamps
TimeCols = contains([txtArray(1,:)],’Time’,’IgnoreCase’,true);
% convert times to numerical values
times = datetime([txtArray(2:end,TimeCols)],’InputFormat’,’M/d/yyyy h:m:ss.SSS a’);
NoVars = sum(~TimeCols);
for j=1:NoVars
% create time column in TimeTable
TC = times(:,j);
% create data column in TimeTable
DC = cellfun(@(s) str2double(s),txtArray(:,2*j));
% merge arrays into Timetable, remove invalied (NaT) times
TT(j).tt = array2timetable(DC(~isnat(TC)),’RowTimes’,TC(~isnat(TC)));
end
% merge timetables
for j=1:NoVars
if ~issorted(TT(j).tt);
TT(j).tt=sortrows(TT(j).tt);
end
if j>1
if j==2
Ttable = TT(j-1).tt;
end
% synchronize removes dublicate times
Ttable = synchronize(Ttable,TT(j).tt); % https://mathworks.com/help/matlab/ref/timetable.synchronize.html
Ttable = fillmissing(Ttable,’previous’); % https://mathworks.com/help/matlab/ref/fillmissing.html
end
end
% fill missing values for the first lines which may still be empty
Ttable = fillmissing(Ttable,’next’);
% rename properties
Ttable.Properties.VariableNames = {‘Var1′,’Var2′,’Var3’}; I’ve got files which contain data multiple from multiple sensors. Each sensor has it’s own timestamp. Not all sensors have the same number of values.
Currently I’m splitting the file into several timetables. Then I’ll merge and synchronize the timetables and finally fill the missing values.
Is there a better way to do this, since the original files contain several hundred thousand lines for 50-60 signals?
txtArray= {‘Sig1_Time’ ‘Sig1_Value’ ‘Signal2_Time’ ‘Sig2_Value’ ‘Sig3_Time’ ‘Sig3_Value’;
‘4/28/2020 6:41:56.555 PM’ ‘92.1822814’ ‘4/28/2020 6:41:56.545 PM’ ‘21.2642456’ ‘4/28/2020 6:40:56.545 PM’ ‘1.26’;
‘4/28/2020 6:42:06.655 PM’ ‘92.2822814’ ‘4/28/2020 6:42:06.645 PM’ ‘22.3538671’ ‘4/28/2020 6:50:06.645 PM’ ‘2.35’;
‘4/28/2020 6:42:07.665 PM’ ‘92.1922814’ ‘4/28/2020 6:42:07.655 PM’ ‘22.2642456’ ” ”;
” ” ‘4/28/2020 6:42:08.665 PM’ ‘23.2822436’ ” ”;
” ” ‘4/28/2020 6:42:20.786 PM’ ‘22.2642456’ ” ”;
};
% find columns with timestamps
TimeCols = contains([txtArray(1,:)],’Time’,’IgnoreCase’,true);
% convert times to numerical values
times = datetime([txtArray(2:end,TimeCols)],’InputFormat’,’M/d/yyyy h:m:ss.SSS a’);
NoVars = sum(~TimeCols);
for j=1:NoVars
% create time column in TimeTable
TC = times(:,j);
% create data column in TimeTable
DC = cellfun(@(s) str2double(s),txtArray(:,2*j));
% merge arrays into Timetable, remove invalied (NaT) times
TT(j).tt = array2timetable(DC(~isnat(TC)),’RowTimes’,TC(~isnat(TC)));
end
% merge timetables
for j=1:NoVars
if ~issorted(TT(j).tt);
TT(j).tt=sortrows(TT(j).tt);
end
if j>1
if j==2
Ttable = TT(j-1).tt;
end
% synchronize removes dublicate times
Ttable = synchronize(Ttable,TT(j).tt); % https://mathworks.com/help/matlab/ref/timetable.synchronize.html
Ttable = fillmissing(Ttable,’previous’); % https://mathworks.com/help/matlab/ref/fillmissing.html
end
end
% fill missing values for the first lines which may still be empty
Ttable = fillmissing(Ttable,’next’);
% rename properties
Ttable.Properties.VariableNames = {‘Var1′,’Var2′,’Var3’}; timetable, data import, array2timetable, multiple time columns MATLAB Answers — New Questions
How to fill the space between two surfaces?
If f1(x,y)≤z≤f2(x,y), how to draw the range of z? If the upper and lower limits of z are described by separate functions, how to plot the range of the z function in the direction of the z-axis instead of two surfaces?
x=-5:0.1:5;
y=-5:0.1:5;
[XX,YY]=meshgrid(x,y);
for m=1:101
for n=1:101
z1(m,n)=x(m)^2+y(n)^2;
z2(m,n)=3*x(m)^3+y(n)^2+1;
plot3([XX(m,n) XX(m,n)],[YY(m,n) YY(m,n)],[z1(m,n) z2(m,n)])
hold on
end
end
hold on
The code to draw only 2 surfaces is given here.
x=-5:0.1:5;
y=-5:0.1:5;
for m=1:101
for n=1:101
z1(m,n)=x(m)^2+y(n)^2;
z2(m,n)=3*x(m)^3+y(n)^2+1;
end
end
surf(x,y,z1,"EdgeColor","none")
hold on
surf(x,y,z2,"EdgeColor","none")If f1(x,y)≤z≤f2(x,y), how to draw the range of z? If the upper and lower limits of z are described by separate functions, how to plot the range of the z function in the direction of the z-axis instead of two surfaces?
x=-5:0.1:5;
y=-5:0.1:5;
[XX,YY]=meshgrid(x,y);
for m=1:101
for n=1:101
z1(m,n)=x(m)^2+y(n)^2;
z2(m,n)=3*x(m)^3+y(n)^2+1;
plot3([XX(m,n) XX(m,n)],[YY(m,n) YY(m,n)],[z1(m,n) z2(m,n)])
hold on
end
end
hold on
The code to draw only 2 surfaces is given here.
x=-5:0.1:5;
y=-5:0.1:5;
for m=1:101
for n=1:101
z1(m,n)=x(m)^2+y(n)^2;
z2(m,n)=3*x(m)^3+y(n)^2+1;
end
end
surf(x,y,z1,"EdgeColor","none")
hold on
surf(x,y,z2,"EdgeColor","none") If f1(x,y)≤z≤f2(x,y), how to draw the range of z? If the upper and lower limits of z are described by separate functions, how to plot the range of the z function in the direction of the z-axis instead of two surfaces?
x=-5:0.1:5;
y=-5:0.1:5;
[XX,YY]=meshgrid(x,y);
for m=1:101
for n=1:101
z1(m,n)=x(m)^2+y(n)^2;
z2(m,n)=3*x(m)^3+y(n)^2+1;
plot3([XX(m,n) XX(m,n)],[YY(m,n) YY(m,n)],[z1(m,n) z2(m,n)])
hold on
end
end
hold on
The code to draw only 2 surfaces is given here.
x=-5:0.1:5;
y=-5:0.1:5;
for m=1:101
for n=1:101
z1(m,n)=x(m)^2+y(n)^2;
z2(m,n)=3*x(m)^3+y(n)^2+1;
end
end
surf(x,y,z1,"EdgeColor","none")
hold on
surf(x,y,z2,"EdgeColor","none") filling surface space, three-dimensional drawing MATLAB Answers — New Questions
Why is my table getting all the same values when it shouldn’t?
For some reason my code to automatically fill in a table is running but it’s outputting the same value for all the columns. Which it shouldn’t be getting and I can’t figure out why.
All necessary codes to run this properly are attached and should be run as follows to get a proper output: Lab2PartA -> Select "Example1.txt" when prompted -> DeranAutoTableAttempt
Here is my code:
% Set the value of R as depicted in Table 1 and set C = 1.2 ml/mmHg and run the model
R = [0.50, 0.75, 1, 1.25, 1.5, 1.75, 2];
%% Basline (a1_b) of R is 1.2
a1_b = 1.2;
%Prep to run simulink
C = 1.2;
%Prep Table 1
k = 1;
j = 1 + height(Table1);
R = 0.5:0.25:2;
Z = zeros(size(R));
Table1 = table(R(:),Z(:),Z(:),Z(:),Z(:),…
‘VariableNames’,{‘R (mmHg*s/ml)’ ‘Pressure Maximum (mmHg)’ ‘Pressure Minimum (mmHg)’ ‘Presure Mean (mmHg)’ ‘Pulse Pressure (max-min) (mmHg)’});
while k ~= j
fprintf("R = %d", R(k))
sim(‘ArterialModel2E’)
run MinMax.m;
MinMaxTab = [maxPModel; minPModel; meanPModel];
Table1{k,2} = MinMaxTab(1,1);
Table1{k,3} = MinMaxTab(2,1);
Table1{k,4} = MinMaxTab(3,1);
Table1{k,5} = Table1{k,3}-Table1{k,2};
k = k+1;
end
Table1
% Now set C equal to the value in Table 2 and set R = 1 ml/mmHg
C = [0.6, 0.9, 1.2, 1.5, 1.8, 2.1, 2.4];
% Baseline (a2_b) of C is 1.2
a2_b = 1.2;
% Prep to run simulink
R = 1;
% Prep Table 2
k = 1;
j = 1 + height(Table1);
C = 0.6:0.3:2.4;
Z = zeros(size(C));
Table2 = table(C(:),Z(:),Z(:),Z(:),Z(:),…
‘VariableNames’,{‘C (mmHg*s/ml)’ ‘Pressure Maximum (mmHg)’ ‘Pressure Minimum (mmHg)’ ‘Presure Mean (mmHg)’ ‘Pulse Pressure (max-min) (mmHg)’});
while k ~= j
fprintf("C = %d", C(k))
sim(‘ArterialModel2E’)
run MinMax.m;
MinMaxTab = [maxPModel; minPModel; meanPModel];
Table2{k,2} = MinMaxTab(1,1);
Table2{k,3} = MinMaxTab(2,1);
Table2{k,4} = MinMaxTab(3,1);
Table2{k,5} = Table2{k,3}-Table2{k,2};
k = k+1;
end
Table2
Table 1 results should be:
Table 2 should be:For some reason my code to automatically fill in a table is running but it’s outputting the same value for all the columns. Which it shouldn’t be getting and I can’t figure out why.
All necessary codes to run this properly are attached and should be run as follows to get a proper output: Lab2PartA -> Select "Example1.txt" when prompted -> DeranAutoTableAttempt
Here is my code:
% Set the value of R as depicted in Table 1 and set C = 1.2 ml/mmHg and run the model
R = [0.50, 0.75, 1, 1.25, 1.5, 1.75, 2];
%% Basline (a1_b) of R is 1.2
a1_b = 1.2;
%Prep to run simulink
C = 1.2;
%Prep Table 1
k = 1;
j = 1 + height(Table1);
R = 0.5:0.25:2;
Z = zeros(size(R));
Table1 = table(R(:),Z(:),Z(:),Z(:),Z(:),…
‘VariableNames’,{‘R (mmHg*s/ml)’ ‘Pressure Maximum (mmHg)’ ‘Pressure Minimum (mmHg)’ ‘Presure Mean (mmHg)’ ‘Pulse Pressure (max-min) (mmHg)’});
while k ~= j
fprintf("R = %d", R(k))
sim(‘ArterialModel2E’)
run MinMax.m;
MinMaxTab = [maxPModel; minPModel; meanPModel];
Table1{k,2} = MinMaxTab(1,1);
Table1{k,3} = MinMaxTab(2,1);
Table1{k,4} = MinMaxTab(3,1);
Table1{k,5} = Table1{k,3}-Table1{k,2};
k = k+1;
end
Table1
% Now set C equal to the value in Table 2 and set R = 1 ml/mmHg
C = [0.6, 0.9, 1.2, 1.5, 1.8, 2.1, 2.4];
% Baseline (a2_b) of C is 1.2
a2_b = 1.2;
% Prep to run simulink
R = 1;
% Prep Table 2
k = 1;
j = 1 + height(Table1);
C = 0.6:0.3:2.4;
Z = zeros(size(C));
Table2 = table(C(:),Z(:),Z(:),Z(:),Z(:),…
‘VariableNames’,{‘C (mmHg*s/ml)’ ‘Pressure Maximum (mmHg)’ ‘Pressure Minimum (mmHg)’ ‘Presure Mean (mmHg)’ ‘Pulse Pressure (max-min) (mmHg)’});
while k ~= j
fprintf("C = %d", C(k))
sim(‘ArterialModel2E’)
run MinMax.m;
MinMaxTab = [maxPModel; minPModel; meanPModel];
Table2{k,2} = MinMaxTab(1,1);
Table2{k,3} = MinMaxTab(2,1);
Table2{k,4} = MinMaxTab(3,1);
Table2{k,5} = Table2{k,3}-Table2{k,2};
k = k+1;
end
Table2
Table 1 results should be:
Table 2 should be: For some reason my code to automatically fill in a table is running but it’s outputting the same value for all the columns. Which it shouldn’t be getting and I can’t figure out why.
All necessary codes to run this properly are attached and should be run as follows to get a proper output: Lab2PartA -> Select "Example1.txt" when prompted -> DeranAutoTableAttempt
Here is my code:
% Set the value of R as depicted in Table 1 and set C = 1.2 ml/mmHg and run the model
R = [0.50, 0.75, 1, 1.25, 1.5, 1.75, 2];
%% Basline (a1_b) of R is 1.2
a1_b = 1.2;
%Prep to run simulink
C = 1.2;
%Prep Table 1
k = 1;
j = 1 + height(Table1);
R = 0.5:0.25:2;
Z = zeros(size(R));
Table1 = table(R(:),Z(:),Z(:),Z(:),Z(:),…
‘VariableNames’,{‘R (mmHg*s/ml)’ ‘Pressure Maximum (mmHg)’ ‘Pressure Minimum (mmHg)’ ‘Presure Mean (mmHg)’ ‘Pulse Pressure (max-min) (mmHg)’});
while k ~= j
fprintf("R = %d", R(k))
sim(‘ArterialModel2E’)
run MinMax.m;
MinMaxTab = [maxPModel; minPModel; meanPModel];
Table1{k,2} = MinMaxTab(1,1);
Table1{k,3} = MinMaxTab(2,1);
Table1{k,4} = MinMaxTab(3,1);
Table1{k,5} = Table1{k,3}-Table1{k,2};
k = k+1;
end
Table1
% Now set C equal to the value in Table 2 and set R = 1 ml/mmHg
C = [0.6, 0.9, 1.2, 1.5, 1.8, 2.1, 2.4];
% Baseline (a2_b) of C is 1.2
a2_b = 1.2;
% Prep to run simulink
R = 1;
% Prep Table 2
k = 1;
j = 1 + height(Table1);
C = 0.6:0.3:2.4;
Z = zeros(size(C));
Table2 = table(C(:),Z(:),Z(:),Z(:),Z(:),…
‘VariableNames’,{‘C (mmHg*s/ml)’ ‘Pressure Maximum (mmHg)’ ‘Pressure Minimum (mmHg)’ ‘Presure Mean (mmHg)’ ‘Pulse Pressure (max-min) (mmHg)’});
while k ~= j
fprintf("C = %d", C(k))
sim(‘ArterialModel2E’)
run MinMax.m;
MinMaxTab = [maxPModel; minPModel; meanPModel];
Table2{k,2} = MinMaxTab(1,1);
Table2{k,3} = MinMaxTab(2,1);
Table2{k,4} = MinMaxTab(3,1);
Table2{k,5} = Table2{k,3}-Table2{k,2};
k = k+1;
end
Table2
Table 1 results should be:
Table 2 should be: simulink, table, while loop MATLAB Answers — New Questions