Tag Archives: matlab
Error: In an assignment A(:) = B, the number of elements in A and B must be the same. while simulating circuit in MATLAB simullink
Every time getting error In an assignment A(:) = B, the number of elements in A and B must be the same. while simulating circuit in MATLAB simullink while simulating circuit in MATLAB simulink
Kindly reslove the issue as early as possibleEvery time getting error In an assignment A(:) = B, the number of elements in A and B must be the same. while simulating circuit in MATLAB simullink while simulating circuit in MATLAB simulink
Kindly reslove the issue as early as possible Every time getting error In an assignment A(:) = B, the number of elements in A and B must be the same. while simulating circuit in MATLAB simullink while simulating circuit in MATLAB simulink
Kindly reslove the issue as early as possible simulink MATLAB Answers — New Questions
Problem with time loop- variables are not updating and being used in the next loop
Hi all, I hope you doing well!
i am trying to simulate the motion of ionic species under electric field. I am using a set of equations such as Poisson equation, drift, and difussion equation (where the coefficient of difussion is related to the electrical mobility through the Eistein relationship), and mass balance equation for continuity. My code seems fine and it give me a reasonble results for the first time step. However, nothing change after that and i get the same results for each time step. The ionic species are supposed to move with the electric field and the concentration profile will change. That new concentration profile will be used to calculate the new potential, new electric field, and new charge density. But, anything i do seems to work to be able to see those changes.Hi all, I hope you doing well!
i am trying to simulate the motion of ionic species under electric field. I am using a set of equations such as Poisson equation, drift, and difussion equation (where the coefficient of difussion is related to the electrical mobility through the Eistein relationship), and mass balance equation for continuity. My code seems fine and it give me a reasonble results for the first time step. However, nothing change after that and i get the same results for each time step. The ionic species are supposed to move with the electric field and the concentration profile will change. That new concentration profile will be used to calculate the new potential, new electric field, and new charge density. But, anything i do seems to work to be able to see those changes. Hi all, I hope you doing well!
i am trying to simulate the motion of ionic species under electric field. I am using a set of equations such as Poisson equation, drift, and difussion equation (where the coefficient of difussion is related to the electrical mobility through the Eistein relationship), and mass balance equation for continuity. My code seems fine and it give me a reasonble results for the first time step. However, nothing change after that and i get the same results for each time step. The ionic species are supposed to move with the electric field and the concentration profile will change. That new concentration profile will be used to calculate the new potential, new electric field, and new charge density. But, anything i do seems to work to be able to see those changes. ion migration, electric field MATLAB Answers — New Questions
Using the mouse to select drag scope measurement cursors
Using 2016b, I need to measure pulse timings from a standard Simulink scope. It does not seem to be possible to select and drag them using the mouse.
The keyboard commands don’t seem to work either.Using 2016b, I need to measure pulse timings from a standard Simulink scope. It does not seem to be possible to select and drag them using the mouse.
The keyboard commands don’t seem to work either. Using 2016b, I need to measure pulse timings from a standard Simulink scope. It does not seem to be possible to select and drag them using the mouse.
The keyboard commands don’t seem to work either. scope, cursor MATLAB Answers — New Questions
how to correctly use the function “subs”
Hi there,
I am using subs to replace some symbols in a symbolic expression Jacobian_mtx_1. The symbols that I want to be replaced are A, B and C, which are a 6*1 symbolic vector, a symbolic scalar, and a 2*1 symbolic vector, respectively. I write the code:
Jacobian_mtx_1 = subs( Jacobian_mtx_1 , { A , B , C } , { A_val ,B_val , C_val } ) ;
where A_val is a 6*1 vector containing 6 function calls, B_val is a numeric scalar, and C_val is a 2*1 numeric vector.
However, the software reminds me that
Errors using sym/subs
Entries in second argument must be scalar.
Could anyone tell me how to resolve this issue?
Many thanks!Hi there,
I am using subs to replace some symbols in a symbolic expression Jacobian_mtx_1. The symbols that I want to be replaced are A, B and C, which are a 6*1 symbolic vector, a symbolic scalar, and a 2*1 symbolic vector, respectively. I write the code:
Jacobian_mtx_1 = subs( Jacobian_mtx_1 , { A , B , C } , { A_val ,B_val , C_val } ) ;
where A_val is a 6*1 vector containing 6 function calls, B_val is a numeric scalar, and C_val is a 2*1 numeric vector.
However, the software reminds me that
Errors using sym/subs
Entries in second argument must be scalar.
Could anyone tell me how to resolve this issue?
Many thanks! Hi there,
I am using subs to replace some symbols in a symbolic expression Jacobian_mtx_1. The symbols that I want to be replaced are A, B and C, which are a 6*1 symbolic vector, a symbolic scalar, and a 2*1 symbolic vector, respectively. I write the code:
Jacobian_mtx_1 = subs( Jacobian_mtx_1 , { A , B , C } , { A_val ,B_val , C_val } ) ;
where A_val is a 6*1 vector containing 6 function calls, B_val is a numeric scalar, and C_val is a 2*1 numeric vector.
However, the software reminds me that
Errors using sym/subs
Entries in second argument must be scalar.
Could anyone tell me how to resolve this issue?
Many thanks! subs MATLAB Answers — New Questions
How to add cumulative values of a set of unique combinations within a Table?
Greetings,
I’d like to know if it is possible to add up the cumulative sum from the values in a particular column that comply with the rule of being part of unique combinations of two ore more columns.
Please find below a simple sample code that could serve as illustration.
T = table({‘John’;’Mary’;’John’;’Mary’;’John’;’John’;’Mary’;’John’},…
{‘Lot A’;’Lot A’;’Lot A’;’Lot Z’;’Lot Z’;’Lot A’;’Lot Z’; ‘Lot Z’},…
datetime({’01/07/2015′;’03/08/2015′;’05/25/2014′;’03/26/2016′;’07/08/2009′;…
’03/01/2020′;’08/23/2010′;’06/15/2008′}),[12; 25; 36; 89; 11; 56; 87; 93],…
‘VariableNames’, {‘Salesperson’,’Lot’,’Date’,’Quantity’});
I’d like to know if I can produce a table that would return the cumulative sum of four possible unique combinations that are derived from the "Salesperson" and the "Lot" columns:
John – Lot A, John – Lot Z, Mary – Lot A, Mary – Lot Z
I’d like a table that would merge and add the cumulative sum of what John sold from Lot A, what John sold from Lot Z, what Mary sold from Lot A and what Mary sold from lot Z, which are the only four possible unique combinations derived from Columns 1 & 2 ("Salesperson & Lot").
As for the date, I’d like this solution to be able to include the date column. I know that the date is not part of the inputs required to derive this cumulative sum, but I’d like each unique combinations to include either the earliest or latest date.
Thank you in advance for your help.Greetings,
I’d like to know if it is possible to add up the cumulative sum from the values in a particular column that comply with the rule of being part of unique combinations of two ore more columns.
Please find below a simple sample code that could serve as illustration.
T = table({‘John’;’Mary’;’John’;’Mary’;’John’;’John’;’Mary’;’John’},…
{‘Lot A’;’Lot A’;’Lot A’;’Lot Z’;’Lot Z’;’Lot A’;’Lot Z’; ‘Lot Z’},…
datetime({’01/07/2015′;’03/08/2015′;’05/25/2014′;’03/26/2016′;’07/08/2009′;…
’03/01/2020′;’08/23/2010′;’06/15/2008′}),[12; 25; 36; 89; 11; 56; 87; 93],…
‘VariableNames’, {‘Salesperson’,’Lot’,’Date’,’Quantity’});
I’d like to know if I can produce a table that would return the cumulative sum of four possible unique combinations that are derived from the "Salesperson" and the "Lot" columns:
John – Lot A, John – Lot Z, Mary – Lot A, Mary – Lot Z
I’d like a table that would merge and add the cumulative sum of what John sold from Lot A, what John sold from Lot Z, what Mary sold from Lot A and what Mary sold from lot Z, which are the only four possible unique combinations derived from Columns 1 & 2 ("Salesperson & Lot").
As for the date, I’d like this solution to be able to include the date column. I know that the date is not part of the inputs required to derive this cumulative sum, but I’d like each unique combinations to include either the earliest or latest date.
Thank you in advance for your help. Greetings,
I’d like to know if it is possible to add up the cumulative sum from the values in a particular column that comply with the rule of being part of unique combinations of two ore more columns.
Please find below a simple sample code that could serve as illustration.
T = table({‘John’;’Mary’;’John’;’Mary’;’John’;’John’;’Mary’;’John’},…
{‘Lot A’;’Lot A’;’Lot A’;’Lot Z’;’Lot Z’;’Lot A’;’Lot Z’; ‘Lot Z’},…
datetime({’01/07/2015′;’03/08/2015′;’05/25/2014′;’03/26/2016′;’07/08/2009′;…
’03/01/2020′;’08/23/2010′;’06/15/2008′}),[12; 25; 36; 89; 11; 56; 87; 93],…
‘VariableNames’, {‘Salesperson’,’Lot’,’Date’,’Quantity’});
I’d like to know if I can produce a table that would return the cumulative sum of four possible unique combinations that are derived from the "Salesperson" and the "Lot" columns:
John – Lot A, John – Lot Z, Mary – Lot A, Mary – Lot Z
I’d like a table that would merge and add the cumulative sum of what John sold from Lot A, what John sold from Lot Z, what Mary sold from Lot A and what Mary sold from lot Z, which are the only four possible unique combinations derived from Columns 1 & 2 ("Salesperson & Lot").
As for the date, I’d like this solution to be able to include the date column. I know that the date is not part of the inputs required to derive this cumulative sum, but I’d like each unique combinations to include either the earliest or latest date.
Thank you in advance for your help. unique, accumarray, table MATLAB Answers — New Questions
Find an older version of a SImulink model
Is there a way to find an older version of a model in Simulink? The model I am currently working with is version 4.3 of itself, but I want to know if I can find the previous versions?
Thank you in advance.Is there a way to find an older version of a model in Simulink? The model I am currently working with is version 4.3 of itself, but I want to know if I can find the previous versions?
Thank you in advance. Is there a way to find an older version of a model in Simulink? The model I am currently working with is version 4.3 of itself, but I want to know if I can find the previous versions?
Thank you in advance. older version, simulink, model, model version MATLAB Answers — New Questions
Regarding the Gaussian filtering function imgaussfilt and the filter function fspecial.
I want to perform Gaussian filtering on an image, but the size of the filter will continue to increase as the program progresses, while the image is getting smaller and smaller. This inevitably leads to a situation where the image size is smaller than the filter size. So, I used these two functions to give a simple example to see if they can work properly.
Now that the execution has ended, I find that the results of the two functions are not the same. I would like to ask if these two functions have different ways of handling the issue of exceeding the matrix boundary? And which function would be more recommended for Gaussian filtering of images in image processing?
a = [1 2 1; 2 1 2; 1 2 1];
% imgaussfilt函数滤波对于边界像素的处理
b = imgaussfilt(a, 1.6);
disp(b);
% 使用same约束矩阵大小,对边界像素的处理
sigma = 1.6;
size = 9;
gaussian_kernel = fspecial(‘gaussian’, size, sigma);
% disp(gaussian_kernel);
c = conv2(a, gaussian_kernel, ‘same’);
disp(c);I want to perform Gaussian filtering on an image, but the size of the filter will continue to increase as the program progresses, while the image is getting smaller and smaller. This inevitably leads to a situation where the image size is smaller than the filter size. So, I used these two functions to give a simple example to see if they can work properly.
Now that the execution has ended, I find that the results of the two functions are not the same. I would like to ask if these two functions have different ways of handling the issue of exceeding the matrix boundary? And which function would be more recommended for Gaussian filtering of images in image processing?
a = [1 2 1; 2 1 2; 1 2 1];
% imgaussfilt函数滤波对于边界像素的处理
b = imgaussfilt(a, 1.6);
disp(b);
% 使用same约束矩阵大小,对边界像素的处理
sigma = 1.6;
size = 9;
gaussian_kernel = fspecial(‘gaussian’, size, sigma);
% disp(gaussian_kernel);
c = conv2(a, gaussian_kernel, ‘same’);
disp(c); I want to perform Gaussian filtering on an image, but the size of the filter will continue to increase as the program progresses, while the image is getting smaller and smaller. This inevitably leads to a situation where the image size is smaller than the filter size. So, I used these two functions to give a simple example to see if they can work properly.
Now that the execution has ended, I find that the results of the two functions are not the same. I would like to ask if these two functions have different ways of handling the issue of exceeding the matrix boundary? And which function would be more recommended for Gaussian filtering of images in image processing?
a = [1 2 1; 2 1 2; 1 2 1];
% imgaussfilt函数滤波对于边界像素的处理
b = imgaussfilt(a, 1.6);
disp(b);
% 使用same约束矩阵大小,对边界像素的处理
sigma = 1.6;
size = 9;
gaussian_kernel = fspecial(‘gaussian’, size, sigma);
% disp(gaussian_kernel);
c = conv2(a, gaussian_kernel, ‘same’);
disp(c); fspecial,imgaussfilt,gauss,filter MATLAB Answers — New Questions
Higher order transfer function precision issue
Hi,
I’m creating a transfer function at higher order (to the degree of 80) by multiplication of many 2nd order transfer function. However, when I get this final transfer function, the result returned is NaN.
I suspect it is due to the precision error in MATLAB, and tried to use vpa commend. It didn’t solve the problem by giving errors.
Could anyone advise me a solution please? thank you.
Steven
num_bnotch=vpa([1 4*0.20*pi*19.5 (2*pi*20.04)^2]);
den_bnotch=vpa([1 4900.88 1.5855e+004]);
bnotch=tf(num_bnotch,den_bnotch)
??? Error using ==> tf.tf at 251
The values of the "num" and "den" properties must be row vectors or cell arrays of row vectors, where each vector is
nonempty and containing numeric data. Type "ltiprops tf" for more information.Hi,
I’m creating a transfer function at higher order (to the degree of 80) by multiplication of many 2nd order transfer function. However, when I get this final transfer function, the result returned is NaN.
I suspect it is due to the precision error in MATLAB, and tried to use vpa commend. It didn’t solve the problem by giving errors.
Could anyone advise me a solution please? thank you.
Steven
num_bnotch=vpa([1 4*0.20*pi*19.5 (2*pi*20.04)^2]);
den_bnotch=vpa([1 4900.88 1.5855e+004]);
bnotch=tf(num_bnotch,den_bnotch)
??? Error using ==> tf.tf at 251
The values of the "num" and "den" properties must be row vectors or cell arrays of row vectors, where each vector is
nonempty and containing numeric data. Type "ltiprops tf" for more information. Hi,
I’m creating a transfer function at higher order (to the degree of 80) by multiplication of many 2nd order transfer function. However, when I get this final transfer function, the result returned is NaN.
I suspect it is due to the precision error in MATLAB, and tried to use vpa commend. It didn’t solve the problem by giving errors.
Could anyone advise me a solution please? thank you.
Steven
num_bnotch=vpa([1 4*0.20*pi*19.5 (2*pi*20.04)^2]);
den_bnotch=vpa([1 4900.88 1.5855e+004]);
bnotch=tf(num_bnotch,den_bnotch)
??? Error using ==> tf.tf at 251
The values of the "num" and "den" properties must be row vectors or cell arrays of row vectors, where each vector is
nonempty and containing numeric data. Type "ltiprops tf" for more information. transfer function, vpa, precision MATLAB Answers — New Questions
Derive full formula from fitlm(X,y,”quadratic”)
I have X which is a 258×6 double and y which is a 258×1 double. These are used to fit a model utilizing fitlm. I found the quadratic to yield the best results.
X = outTableNumeric{:, corr_ids}; % Using the most correlated features
y = outTableNumeric.target; % Target variabel
% Fit a linear regression model
mdl = fitlm(X, y, "quadratic");
However when I try to derive a formula to be deployed outside matlab I find it extremely obscure how I’m to combine the quadratic terms with the coefficients and so on?
I tried to make the formula programmatically but that is not working when I test the result on some row of X.
coefficients = mdl.Coefficients.Estimate;
% Extract the simple notation of the formula
intercept = coefficients(1);
formula = sprintf(‘%.2f’, intercept);
for i = 2:length(coefficients)
if coefficients(i) ~= 0
feature_indices = find(strcmp(mdl.CoefficientNames, mdl.CoefficientNames{i}));
feature_name = mdl.CoefficientNames{feature_indices(1)};
formula = sprintf(‘%s + %.2f * %s’, formula, coefficients(i), feature_name);
end
end
strrep(formula,’:’,’*’);
disp(‘Simple notation of the formula:’);
disp(formula);
Can you please help me extract the full equation?I have X which is a 258×6 double and y which is a 258×1 double. These are used to fit a model utilizing fitlm. I found the quadratic to yield the best results.
X = outTableNumeric{:, corr_ids}; % Using the most correlated features
y = outTableNumeric.target; % Target variabel
% Fit a linear regression model
mdl = fitlm(X, y, "quadratic");
However when I try to derive a formula to be deployed outside matlab I find it extremely obscure how I’m to combine the quadratic terms with the coefficients and so on?
I tried to make the formula programmatically but that is not working when I test the result on some row of X.
coefficients = mdl.Coefficients.Estimate;
% Extract the simple notation of the formula
intercept = coefficients(1);
formula = sprintf(‘%.2f’, intercept);
for i = 2:length(coefficients)
if coefficients(i) ~= 0
feature_indices = find(strcmp(mdl.CoefficientNames, mdl.CoefficientNames{i}));
feature_name = mdl.CoefficientNames{feature_indices(1)};
formula = sprintf(‘%s + %.2f * %s’, formula, coefficients(i), feature_name);
end
end
strrep(formula,’:’,’*’);
disp(‘Simple notation of the formula:’);
disp(formula);
Can you please help me extract the full equation? I have X which is a 258×6 double and y which is a 258×1 double. These are used to fit a model utilizing fitlm. I found the quadratic to yield the best results.
X = outTableNumeric{:, corr_ids}; % Using the most correlated features
y = outTableNumeric.target; % Target variabel
% Fit a linear regression model
mdl = fitlm(X, y, "quadratic");
However when I try to derive a formula to be deployed outside matlab I find it extremely obscure how I’m to combine the quadratic terms with the coefficients and so on?
I tried to make the formula programmatically but that is not working when I test the result on some row of X.
coefficients = mdl.Coefficients.Estimate;
% Extract the simple notation of the formula
intercept = coefficients(1);
formula = sprintf(‘%.2f’, intercept);
for i = 2:length(coefficients)
if coefficients(i) ~= 0
feature_indices = find(strcmp(mdl.CoefficientNames, mdl.CoefficientNames{i}));
feature_name = mdl.CoefficientNames{feature_indices(1)};
formula = sprintf(‘%s + %.2f * %s’, formula, coefficients(i), feature_name);
end
end
strrep(formula,’:’,’*’);
disp(‘Simple notation of the formula:’);
disp(formula);
Can you please help me extract the full equation? #fitlm MATLAB Answers — New Questions
GUI IN MATLAB 2021B, HOW TO SELSCT LISTBOX
HI
how i change the color map of figure in GUI by ListBox Items:{ jet hot cool …..} using GUIHI
how i change the color map of figure in GUI by ListBox Items:{ jet hot cool …..} using GUI HI
how i change the color map of figure in GUI by ListBox Items:{ jet hot cool …..} using GUI guide, gui, matlab gui, colormap, listbox, text, figure MATLAB Answers — New Questions
how to run simulink simulation from matlab script
hello i need to run simulink simulation from matlab, how to do it using matlab command in script ?hello i need to run simulink simulation from matlab, how to do it using matlab command in script ? hello i need to run simulink simulation from matlab, how to do it using matlab command in script ? simulink, run function MATLAB Answers — New Questions
How do I use objects with inheritance structures in a `parfor` loop in Matlab?
I am trying to parallelize a simulation that uses a custom library. Within the ‘parfor’ loop I am using, I receive the following error:
Error using sensor/readdata
Unrecognized field name "sensorDevice".
The object is an instance of Sensor that inherits its .sensorDevice field from its parent class. The method readdata calls on the inherited field. This works fine in a for loop. The transparency requirements for variable definitions and the corresponding documentation emphasize the ability of all variables to be machine-readable, but I do not follow why the parfor loop cannot trace the pointers to the parent classes’ fields and methods. Re-writing the class in a flattened structure is not an option due to the time that would be required to do so.
How do I use methods and fields from a parent class in an instance of a child class in a parfor loop?I am trying to parallelize a simulation that uses a custom library. Within the ‘parfor’ loop I am using, I receive the following error:
Error using sensor/readdata
Unrecognized field name "sensorDevice".
The object is an instance of Sensor that inherits its .sensorDevice field from its parent class. The method readdata calls on the inherited field. This works fine in a for loop. The transparency requirements for variable definitions and the corresponding documentation emphasize the ability of all variables to be machine-readable, but I do not follow why the parfor loop cannot trace the pointers to the parent classes’ fields and methods. Re-writing the class in a flattened structure is not an option due to the time that would be required to do so.
How do I use methods and fields from a parent class in an instance of a child class in a parfor loop? I am trying to parallelize a simulation that uses a custom library. Within the ‘parfor’ loop I am using, I receive the following error:
Error using sensor/readdata
Unrecognized field name "sensorDevice".
The object is an instance of Sensor that inherits its .sensorDevice field from its parent class. The method readdata calls on the inherited field. This works fine in a for loop. The transparency requirements for variable definitions and the corresponding documentation emphasize the ability of all variables to be machine-readable, but I do not follow why the parfor loop cannot trace the pointers to the parent classes’ fields and methods. Re-writing the class in a flattened structure is not an option due to the time that would be required to do so.
How do I use methods and fields from a parent class in an instance of a child class in a parfor loop? parfor, parallel computing MATLAB Answers — New Questions
Run Simulink Model via parsim() and save after each simulation
I am trying to run my simulink model in parallel while saving the results to a matfile after each simulation has completed.
Each worker should take the following action:
Simulate model with simIn( j )
Create matfile for above simulation
Repeate with simIn ( K ) until all simulations are complete.
The below code is my starting point. "test_model" is a simulink model of only a sin wave going into a gain, integrator, and to workspace block simply to test out parsim().
%% Example of how to run simulink models in parallel
clear; close all; clc;
mdl = "test_model";
amp= 1:10;
freq = 1:10;
nSims = length(amp);
simIn(1:nSims) = Simulink.SimulationInput(mdl);
% Setup model workspace
k = 5;
for i =1:nSims
nm = [num2str(i) ‘.mat’];
simIn(i) = setVariable(simIn(i), "amp", amp(i), ‘Workspace’, mdl);
simIn(i) = setVariable(simIn(i), "freq", freq(i), ‘Workspace’, mdl);
simIn(i) = setPostSimFcn(simIn(i), @(x)postSim(x, simIn(i), nm));
end
out = parsim (simIn, ‘UseFastRestart’,’on’, ‘TransferBaseWorkspaceVariables’,’on’);
function postSim(out, in, nm)
% postSim – Run @ completion of each simulation
% Saves simulation input, output, and name to file "nm"
m = matfile(nm, ‘Writable’, true);
m.out = out;
m.in = in;
m.nm = nm;
end
I understand that save() does not work as expected in parallel, so I’ve implemented the example from the question below as a method of creating my mat files. The above code works exactly as expected if "parsim" is replaced with "sim"; however, no files are created when using "parsim".
https://www.mathworks.com/matlabcentral/answers/135285-how-do-i-use-save-with-a-parfor-loop-using-parallel-computing-toolbox
Note: setting ‘TransferBaseWorkspaceVariables’ to ‘off’ and setting k via setVariable does not have any impact on this behavior.
Ask: How can I modify the above code to also work with the parsim command?I am trying to run my simulink model in parallel while saving the results to a matfile after each simulation has completed.
Each worker should take the following action:
Simulate model with simIn( j )
Create matfile for above simulation
Repeate with simIn ( K ) until all simulations are complete.
The below code is my starting point. "test_model" is a simulink model of only a sin wave going into a gain, integrator, and to workspace block simply to test out parsim().
%% Example of how to run simulink models in parallel
clear; close all; clc;
mdl = "test_model";
amp= 1:10;
freq = 1:10;
nSims = length(amp);
simIn(1:nSims) = Simulink.SimulationInput(mdl);
% Setup model workspace
k = 5;
for i =1:nSims
nm = [num2str(i) ‘.mat’];
simIn(i) = setVariable(simIn(i), "amp", amp(i), ‘Workspace’, mdl);
simIn(i) = setVariable(simIn(i), "freq", freq(i), ‘Workspace’, mdl);
simIn(i) = setPostSimFcn(simIn(i), @(x)postSim(x, simIn(i), nm));
end
out = parsim (simIn, ‘UseFastRestart’,’on’, ‘TransferBaseWorkspaceVariables’,’on’);
function postSim(out, in, nm)
% postSim – Run @ completion of each simulation
% Saves simulation input, output, and name to file "nm"
m = matfile(nm, ‘Writable’, true);
m.out = out;
m.in = in;
m.nm = nm;
end
I understand that save() does not work as expected in parallel, so I’ve implemented the example from the question below as a method of creating my mat files. The above code works exactly as expected if "parsim" is replaced with "sim"; however, no files are created when using "parsim".
https://www.mathworks.com/matlabcentral/answers/135285-how-do-i-use-save-with-a-parfor-loop-using-parallel-computing-toolbox
Note: setting ‘TransferBaseWorkspaceVariables’ to ‘off’ and setting k via setVariable does not have any impact on this behavior.
Ask: How can I modify the above code to also work with the parsim command? I am trying to run my simulink model in parallel while saving the results to a matfile after each simulation has completed.
Each worker should take the following action:
Simulate model with simIn( j )
Create matfile for above simulation
Repeate with simIn ( K ) until all simulations are complete.
The below code is my starting point. "test_model" is a simulink model of only a sin wave going into a gain, integrator, and to workspace block simply to test out parsim().
%% Example of how to run simulink models in parallel
clear; close all; clc;
mdl = "test_model";
amp= 1:10;
freq = 1:10;
nSims = length(amp);
simIn(1:nSims) = Simulink.SimulationInput(mdl);
% Setup model workspace
k = 5;
for i =1:nSims
nm = [num2str(i) ‘.mat’];
simIn(i) = setVariable(simIn(i), "amp", amp(i), ‘Workspace’, mdl);
simIn(i) = setVariable(simIn(i), "freq", freq(i), ‘Workspace’, mdl);
simIn(i) = setPostSimFcn(simIn(i), @(x)postSim(x, simIn(i), nm));
end
out = parsim (simIn, ‘UseFastRestart’,’on’, ‘TransferBaseWorkspaceVariables’,’on’);
function postSim(out, in, nm)
% postSim – Run @ completion of each simulation
% Saves simulation input, output, and name to file "nm"
m = matfile(nm, ‘Writable’, true);
m.out = out;
m.in = in;
m.nm = nm;
end
I understand that save() does not work as expected in parallel, so I’ve implemented the example from the question below as a method of creating my mat files. The above code works exactly as expected if "parsim" is replaced with "sim"; however, no files are created when using "parsim".
https://www.mathworks.com/matlabcentral/answers/135285-how-do-i-use-save-with-a-parfor-loop-using-parallel-computing-toolbox
Note: setting ‘TransferBaseWorkspaceVariables’ to ‘off’ and setting k via setVariable does not have any impact on this behavior.
Ask: How can I modify the above code to also work with the parsim command? simulink, parallel computing toolbox MATLAB Answers — New Questions
Controlled Voltage Source (Three-Phase)
After the three-phase voltage signal passes through the Controlled Voltage Source (Three-Phase), the amplitude becomes root three times the original value, and the phase also changes. But according to the module description:
Instantaneous — The output voltages, [va vb vc], are equal to the values of the input port S.
The signal input and output should be same..
Could anyone help me this question? Many thanks.After the three-phase voltage signal passes through the Controlled Voltage Source (Three-Phase), the amplitude becomes root three times the original value, and the phase also changes. But according to the module description:
Instantaneous — The output voltages, [va vb vc], are equal to the values of the input port S.
The signal input and output should be same..
Could anyone help me this question? Many thanks. After the three-phase voltage signal passes through the Controlled Voltage Source (Three-Phase), the amplitude becomes root three times the original value, and the phase also changes. But according to the module description:
Instantaneous — The output voltages, [va vb vc], are equal to the values of the input port S.
The signal input and output should be same..
Could anyone help me this question? Many thanks. controlled voltage source (three-phase) MATLAB Answers — New Questions
A struct in the workspace window consists of n (say 1000 or more) different variable names. How to quickly look for a variable name without any code?
I am having a struct data type that consists of 2000 different names of places with their avg temperatures . When I open the struct variable I get a huge list. How can I quickly locate the variable and read its values without scrolling down to every variable. I don’t see any find option in the window. One may say I can code it. Yes, I can do that but I am looking for alternative quick ways so that I don’t need to write the code to find it.I am having a struct data type that consists of 2000 different names of places with their avg temperatures . When I open the struct variable I get a huge list. How can I quickly locate the variable and read its values without scrolling down to every variable. I don’t see any find option in the window. One may say I can code it. Yes, I can do that but I am looking for alternative quick ways so that I don’t need to write the code to find it. I am having a struct data type that consists of 2000 different names of places with their avg temperatures . When I open the struct variable I get a huge list. How can I quickly locate the variable and read its values without scrolling down to every variable. I don’t see any find option in the window. One may say I can code it. Yes, I can do that but I am looking for alternative quick ways so that I don’t need to write the code to find it. quick variable search in struct variable window MATLAB Answers — New Questions
while writing script for automatic Model advisor check for a model , getting this error
Post Content Post Content automate model advisor, model advisor MATLAB Answers — New Questions
I need to create a polygon or buffer along an irregular shaped coastline in a 2D array of gridded sea temperature data.
I have a 578×235 grid of ocean temperature data in which the land pixels are NaN. I would like to create a 1 pixel buffer around the coastline so that all pixels adjacent to an existing NaN also become NaN. I’m unsure on the best way to do this. I thought I could create a logical array of NaNs and not NaNs but am not sure on the best way to extract a polygon and create the buffer after that step.I have a 578×235 grid of ocean temperature data in which the land pixels are NaN. I would like to create a 1 pixel buffer around the coastline so that all pixels adjacent to an existing NaN also become NaN. I’m unsure on the best way to do this. I thought I could create a logical array of NaNs and not NaNs but am not sure on the best way to extract a polygon and create the buffer after that step. I have a 578×235 grid of ocean temperature data in which the land pixels are NaN. I would like to create a 1 pixel buffer around the coastline so that all pixels adjacent to an existing NaN also become NaN. I’m unsure on the best way to do this. I thought I could create a logical array of NaNs and not NaNs but am not sure on the best way to extract a polygon and create the buffer after that step. extract polygon, buffer MATLAB Answers — New Questions
Training Data type error for a CNN using trainnet function
Trying to use a convolution1dLayer for my sequence input data put when I try to train it i get the error:
"Error using trainnet
Invalid targets. Network expects numeric or categorical targets, but received a cell array."
I’ve looked at many exemples of how the data must be structed but even if is in the same format, it doesn’t work.
For the predictors I’m doing a test with only 4 observations, each one with 4 features and 36191 points:
For the targets there are also for observations with only one target each and also 36191 points:
I can’t understand why it doesn’t accept it, like I said, its equal to many other exemples. I leave down here the code for the CNN-LSTM network and the trainnet function:
lgraph = layerGraph();
tempLayers = [
sequenceInputLayer(4,"Name","input")
convolution1dLayer(4,32,"Name","conv1d","Padding","same")
globalAveragePooling1dLayer("Name","gapool1d")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = lstmLayer(25,"Name","lstm");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = lstmLayer(25,"Name","lstm_1");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
concatenationLayer(1,2,"Name","concat")
lstmLayer(55,"Name","lstm_2")
dropoutLayer(0.5,"Name","drop")
fullyConnectedLayer(1,"Name","fc")
sigmoidLayer("Name","sigmoid")];
lgraph = addLayers(lgraph,tempLayers);
% clean up helper variable
clear tempLayers;
lgraph = connectLayers(lgraph,"gapool1d","lstm");
lgraph = connectLayers(lgraph,"gapool1d","lstm_1");
lgraph = connectLayers(lgraph,"lstm","concat/in1");
lgraph = connectLayers(lgraph,"lstm_1","concat/in2");
plot(lgraph);
epochs = 800;
miniBatchSize = 128;
LRDropPeriod = 200;
InitialLR = 0.01;
LRDropFactor = 0.1;
valFrequency = 30;
options = trainingOptions("adam", …
MaxEpochs=epochs, …
SequencePaddingDirection="left", …
Shuffle="every-epoch", …
GradientThreshold=1, …
InitialLearnRate=InitialLR, …
LearnRateSchedule="piecewise", …
LearnRateDropPeriod=LRDropPeriod, …
LearnRateDropFactor=LRDropFactor, …
MiniBatchSize=miniBatchSize, …
Plots="training-progress", …
Metrics="rmse", …
Verbose=0, …
ExecutionEnvironment="parallel");
CNN_LTSM = trainnet(trainDataX, trainDataY, dlnetwork(lgraph),"mse",options);
using version 2023bTrying to use a convolution1dLayer for my sequence input data put when I try to train it i get the error:
"Error using trainnet
Invalid targets. Network expects numeric or categorical targets, but received a cell array."
I’ve looked at many exemples of how the data must be structed but even if is in the same format, it doesn’t work.
For the predictors I’m doing a test with only 4 observations, each one with 4 features and 36191 points:
For the targets there are also for observations with only one target each and also 36191 points:
I can’t understand why it doesn’t accept it, like I said, its equal to many other exemples. I leave down here the code for the CNN-LSTM network and the trainnet function:
lgraph = layerGraph();
tempLayers = [
sequenceInputLayer(4,"Name","input")
convolution1dLayer(4,32,"Name","conv1d","Padding","same")
globalAveragePooling1dLayer("Name","gapool1d")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = lstmLayer(25,"Name","lstm");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = lstmLayer(25,"Name","lstm_1");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
concatenationLayer(1,2,"Name","concat")
lstmLayer(55,"Name","lstm_2")
dropoutLayer(0.5,"Name","drop")
fullyConnectedLayer(1,"Name","fc")
sigmoidLayer("Name","sigmoid")];
lgraph = addLayers(lgraph,tempLayers);
% clean up helper variable
clear tempLayers;
lgraph = connectLayers(lgraph,"gapool1d","lstm");
lgraph = connectLayers(lgraph,"gapool1d","lstm_1");
lgraph = connectLayers(lgraph,"lstm","concat/in1");
lgraph = connectLayers(lgraph,"lstm_1","concat/in2");
plot(lgraph);
epochs = 800;
miniBatchSize = 128;
LRDropPeriod = 200;
InitialLR = 0.01;
LRDropFactor = 0.1;
valFrequency = 30;
options = trainingOptions("adam", …
MaxEpochs=epochs, …
SequencePaddingDirection="left", …
Shuffle="every-epoch", …
GradientThreshold=1, …
InitialLearnRate=InitialLR, …
LearnRateSchedule="piecewise", …
LearnRateDropPeriod=LRDropPeriod, …
LearnRateDropFactor=LRDropFactor, …
MiniBatchSize=miniBatchSize, …
Plots="training-progress", …
Metrics="rmse", …
Verbose=0, …
ExecutionEnvironment="parallel");
CNN_LTSM = trainnet(trainDataX, trainDataY, dlnetwork(lgraph),"mse",options);
using version 2023b Trying to use a convolution1dLayer for my sequence input data put when I try to train it i get the error:
"Error using trainnet
Invalid targets. Network expects numeric or categorical targets, but received a cell array."
I’ve looked at many exemples of how the data must be structed but even if is in the same format, it doesn’t work.
For the predictors I’m doing a test with only 4 observations, each one with 4 features and 36191 points:
For the targets there are also for observations with only one target each and also 36191 points:
I can’t understand why it doesn’t accept it, like I said, its equal to many other exemples. I leave down here the code for the CNN-LSTM network and the trainnet function:
lgraph = layerGraph();
tempLayers = [
sequenceInputLayer(4,"Name","input")
convolution1dLayer(4,32,"Name","conv1d","Padding","same")
globalAveragePooling1dLayer("Name","gapool1d")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = lstmLayer(25,"Name","lstm");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = lstmLayer(25,"Name","lstm_1");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
concatenationLayer(1,2,"Name","concat")
lstmLayer(55,"Name","lstm_2")
dropoutLayer(0.5,"Name","drop")
fullyConnectedLayer(1,"Name","fc")
sigmoidLayer("Name","sigmoid")];
lgraph = addLayers(lgraph,tempLayers);
% clean up helper variable
clear tempLayers;
lgraph = connectLayers(lgraph,"gapool1d","lstm");
lgraph = connectLayers(lgraph,"gapool1d","lstm_1");
lgraph = connectLayers(lgraph,"lstm","concat/in1");
lgraph = connectLayers(lgraph,"lstm_1","concat/in2");
plot(lgraph);
epochs = 800;
miniBatchSize = 128;
LRDropPeriod = 200;
InitialLR = 0.01;
LRDropFactor = 0.1;
valFrequency = 30;
options = trainingOptions("adam", …
MaxEpochs=epochs, …
SequencePaddingDirection="left", …
Shuffle="every-epoch", …
GradientThreshold=1, …
InitialLearnRate=InitialLR, …
LearnRateSchedule="piecewise", …
LearnRateDropPeriod=LRDropPeriod, …
LearnRateDropFactor=LRDropFactor, …
MiniBatchSize=miniBatchSize, …
Plots="training-progress", …
Metrics="rmse", …
Verbose=0, …
ExecutionEnvironment="parallel");
CNN_LTSM = trainnet(trainDataX, trainDataY, dlnetwork(lgraph),"mse",options);
using version 2023b deep learning, cnn, data, neural network, machine learning MATLAB Answers — New Questions
How to plot cross quantile correltaion heatmap
How do I plot similar cross quantile correlation plotHow do I plot similar cross quantile correlation plot How do I plot similar cross quantile correlation plot heatmap, quantile, correlat MATLAB Answers — New Questions
i am trying to open matlab but it is showing “You dont have a valid license file”. It was working fine before.
i am trying to open matlab but it is showing "You dont have a valid license file". It was working fine before.i am trying to open matlab but it is showing "You dont have a valid license file". It was working fine before. i am trying to open matlab but it is showing "You dont have a valid license file". It was working fine before. valid license file MATLAB Answers — New Questions