Tag Archives: matlab
Possibility to Restore deleted requirement
Hi.
Using Simulink Requirements from the Requirements Error, I deleted a requirement and I was trying to restore it.
Is there any Undo or Restore command or a workaround to solve the problem?
Thanks.Hi.
Using Simulink Requirements from the Requirements Error, I deleted a requirement and I was trying to restore it.
Is there any Undo or Restore command or a workaround to solve the problem?
Thanks. Hi.
Using Simulink Requirements from the Requirements Error, I deleted a requirement and I was trying to restore it.
Is there any Undo or Restore command or a workaround to solve the problem?
Thanks. restore requirement, simulink MATLAB Answers — New Questions
Accessing workspace variables with parallel workers
I have a simulink model that I would like to run a number of times over a range of 2 different variables. In my simulink model I was using model callbacks to take the 2 random initial variables and calculate the initial conditions to some of my integrators but this wasn’t working and now I am doing this in the for loops. However when I run the simulation it throws an error saying "Warning: Error in the simulation was caused by missing variable ‘q_e2b0’. Set "TransferBaseWorkspaceVariables" option to "on" to fix the issue." I tried setting that in setModelParameters but that doesn’t work either.
Below is a pseduo code of my script:
num_sims = length(phi_range)*length(theta_range);
simIn(1:num_sims) = Simulink.SimulationInput(‘SixDOFSimulink’);
sim_itr = 1;
for i = 1:length(phi_range)
for j = 1:length(theta_range)
phi0 = phi_range(i);
theta0 = theta_range(j);
% do calculations %
pos0 = %value%
v_b0 = %value%
w0 = %value%
q_e2b_0 = %value%
simIn(sim_itr) = simIn(sim_itr).setModelParameter(‘SimulationMode’, ‘normal’, …
‘SaveTime’, ‘on’, …
‘SaveOutput’, ‘on’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘theta0’, theta0, ‘workspace’, ‘SixDOFSimulink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘phi0’, phi0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘q_e2b0’, q_e2b0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘v_b0’, v_b0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘pos0’, pos0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘w0’, w0, ‘workspace’, ‘SixDOFSimunlink’);
sim_itr = sim_itr+1;
end
end
out = parsim(simIn, ‘ShowProgress’, ‘on’);
delete(gcp(‘nocreate’))I have a simulink model that I would like to run a number of times over a range of 2 different variables. In my simulink model I was using model callbacks to take the 2 random initial variables and calculate the initial conditions to some of my integrators but this wasn’t working and now I am doing this in the for loops. However when I run the simulation it throws an error saying "Warning: Error in the simulation was caused by missing variable ‘q_e2b0’. Set "TransferBaseWorkspaceVariables" option to "on" to fix the issue." I tried setting that in setModelParameters but that doesn’t work either.
Below is a pseduo code of my script:
num_sims = length(phi_range)*length(theta_range);
simIn(1:num_sims) = Simulink.SimulationInput(‘SixDOFSimulink’);
sim_itr = 1;
for i = 1:length(phi_range)
for j = 1:length(theta_range)
phi0 = phi_range(i);
theta0 = theta_range(j);
% do calculations %
pos0 = %value%
v_b0 = %value%
w0 = %value%
q_e2b_0 = %value%
simIn(sim_itr) = simIn(sim_itr).setModelParameter(‘SimulationMode’, ‘normal’, …
‘SaveTime’, ‘on’, …
‘SaveOutput’, ‘on’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘theta0’, theta0, ‘workspace’, ‘SixDOFSimulink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘phi0’, phi0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘q_e2b0’, q_e2b0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘v_b0’, v_b0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘pos0’, pos0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘w0’, w0, ‘workspace’, ‘SixDOFSimunlink’);
sim_itr = sim_itr+1;
end
end
out = parsim(simIn, ‘ShowProgress’, ‘on’);
delete(gcp(‘nocreate’)) I have a simulink model that I would like to run a number of times over a range of 2 different variables. In my simulink model I was using model callbacks to take the 2 random initial variables and calculate the initial conditions to some of my integrators but this wasn’t working and now I am doing this in the for loops. However when I run the simulation it throws an error saying "Warning: Error in the simulation was caused by missing variable ‘q_e2b0’. Set "TransferBaseWorkspaceVariables" option to "on" to fix the issue." I tried setting that in setModelParameters but that doesn’t work either.
Below is a pseduo code of my script:
num_sims = length(phi_range)*length(theta_range);
simIn(1:num_sims) = Simulink.SimulationInput(‘SixDOFSimulink’);
sim_itr = 1;
for i = 1:length(phi_range)
for j = 1:length(theta_range)
phi0 = phi_range(i);
theta0 = theta_range(j);
% do calculations %
pos0 = %value%
v_b0 = %value%
w0 = %value%
q_e2b_0 = %value%
simIn(sim_itr) = simIn(sim_itr).setModelParameter(‘SimulationMode’, ‘normal’, …
‘SaveTime’, ‘on’, …
‘SaveOutput’, ‘on’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘theta0’, theta0, ‘workspace’, ‘SixDOFSimulink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘phi0’, phi0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘q_e2b0’, q_e2b0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘v_b0’, v_b0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘pos0’, pos0, ‘workspace’, ‘SixDOFSimunlink’);
simIn(sim_itr) = simIn(sim_itr).setVariable(‘w0’, w0, ‘workspace’, ‘SixDOFSimunlink’);
sim_itr = sim_itr+1;
end
end
out = parsim(simIn, ‘ShowProgress’, ‘on’);
delete(gcp(‘nocreate’)) simulink, parallel computing toolbox MATLAB Answers — New Questions
I am having trouble getting the engine speed to 0 rpm when simulating a series hybrid vehicle controller.
Hi, I am having trouble controlling the motor block speed to 0 when the motor start signal is 0. It works fine when I give the motor speed 800rpm when the start signal is 0
However when I give the speed 0 rpm when the signal is 0, the result is that the motor speed decreases.
I have attached the simulink model and the driving cycle I built with this question. It’s built on matlab r2022a and based on the model in the following link: https://www.mathworks.com/help/sdl/ug/series-hybrid-transmission.html
If someone have any idea about a solution to my problem, I will be very grateful.
Thanks in advance to anybody that awnser to this post ! :)Hi, I am having trouble controlling the motor block speed to 0 when the motor start signal is 0. It works fine when I give the motor speed 800rpm when the start signal is 0
However when I give the speed 0 rpm when the signal is 0, the result is that the motor speed decreases.
I have attached the simulink model and the driving cycle I built with this question. It’s built on matlab r2022a and based on the model in the following link: https://www.mathworks.com/help/sdl/ug/series-hybrid-transmission.html
If someone have any idea about a solution to my problem, I will be very grateful.
Thanks in advance to anybody that awnser to this post ! 🙂 Hi, I am having trouble controlling the motor block speed to 0 when the motor start signal is 0. It works fine when I give the motor speed 800rpm when the start signal is 0
However when I give the speed 0 rpm when the signal is 0, the result is that the motor speed decreases.
I have attached the simulink model and the driving cycle I built with this question. It’s built on matlab r2022a and based on the model in the following link: https://www.mathworks.com/help/sdl/ug/series-hybrid-transmission.html
If someone have any idea about a solution to my problem, I will be very grateful.
Thanks in advance to anybody that awnser to this post ! 🙂 speed, control MATLAB Answers — New Questions
How to obtain the average diameter of a segment of a graph?
I have a graph structure that is formed after binarizing an image of blood vessels and obtaining the skeleton, then creating a graph structure. The graph looks like this:
K >> graph =
graph with properties:
Edges: [773×2 table]
Nodes: [773×0 table]
Which means I have 773 edges and each edge has 2 vertices. The graph edges look like this:
EndNodes Weight
__________ ______
1 2 1
1 53 1.4142
2 3 1
3 4 1
4 5 1
Now, at the end of the graph creation, I have other helper functions that help me create a diameters table with points that have been inferred on the binary image between the vessel walls. So, for each graph point the algorithm tries to look for walls and once found it saves the coordinates and other values in a table.
This is how the table gets created and how it looks like:
diam_tab = table();
for i = 1:n_line % for all the lines detected
row = cell(1,7);
row{1} = dt(i,:); % the diameter measured
row{2} = t; % the time dimension
row{3} = fs; % the frame sampling rate
row{4} = squeeze(permute(w1_t(i,:,:), [1, 3, 2])); % The value coordiantes of the first wall
row{5} = squeeze(permute(w2_t(i,:,:), [1, 3, 2])); % The value coordinates of the second wall
row{6} = line_type(i); % just a string, not relevant
row{7} = util.make_uuid(); % an UUID attached
diam_tab = [diam_tab; row];
end
And finally look like this:
y x fs z1 z2 type UUID
______________ ______________ ______ ________________ ________________ ________ ________________________________________
1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘6ada1ae1-00f8-4d9b-aa7a-80c7be26aaa1’}
1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘b8da617c-f55f-418c-88dc-5862c968a637’}
Now, what I want to do is, modify this table so that it doesn’t take all of the 773 rows but instead only like an average of the diameters over a certain segment of the graph. Let’s suppose say that the graph has a Y shape, I would like to obtain, every lets say 10 points an average diameter of that section.
Then, finally, the diam_tab table will not have 773 rows, but only the ones left after averaging over several sections of the graph, let’s say for a graph length of 100 the result would be 100 rows, but I want to get instead the average of the graph at sections of length for ex 10, which would leave me with 10 rows.
And finally, the diam_table would be updated to reflect these values, or at the very least replaced by a similar functioning table.
So far, this is what I turned up with in my code, which isn’t exactly working well as it seems to only get center points between two nodes and then breaks when I attach the created structure to the graph.
function diameters_table = segment_vessel_table(ts, diam_tab)
graph = ts.load_var(‘center_line’).graph;
[y, x] = find(ts.load_var(‘binary_image’));
node_coordinates = [x, y];
n_vessels = height(diam_tab);
midpoints = zeros(n_vessels, 2);
n_samples_graph = 5;
for i = 1:n_vessels
z1 = diam_tab.z1{i};
z2 = diam_tab.z2{i};
mids = (z1 + z2) / 2;
midpoints(i, 🙂 = mean(mids, 2);
end
idx = round(linspace(1, size(z1, 2), n_samples_graph));
sample_points = mean((z1(:, idx) + z2(:, idx)) / 2, 2);
graph = calculate_branch_centers(graph, node_coordinates);
distances = pdist2(midpoints, graph.Nodes.branch_centers);
[~, branch_idx] = min(distances, [], 2);
diam_tab.branch_id = branch_idx;
diameters_table = diam_tab;
end
function graph = calculate_branch_centers(graph, node_coordinates)
n_edges = height(graph.Edges);
branch_centers = zeros(n_edges, 2);
for i = 1:n_edges
node1 = graph.Edges.EndNodes(i, 1);
node2 = graph.Edges.EndNodes(i, 2);
p1 = node_coordinates(node1, :);
p2 = node_coordinates(node2, :);
branch_centers(i, 🙂 = (p1 + p2) / 2;
end
graph.branch_centers = branch_centers; % it breaks here
end
function [xs, x_names, fs] = load_vars(trial)
ts = trial.load_var("tseries");
diam_tab = ts.load_var("diameters");
diam_tab = segment_vessel_table(ts, diam_tab);
dt = diam_tab{:, "y"};
t = diam_tab.x;
t = t(1,:);
xs = TimeSeries(t, dt’);
x_names = "diameter";
% Freq bands is another part that works and not shown atm
for i = 1:size(freq_bands,1)
name = freq_bands{i,1};
xs = [xs; bands.(name)];
x_names = [x_names; name];
end
endI have a graph structure that is formed after binarizing an image of blood vessels and obtaining the skeleton, then creating a graph structure. The graph looks like this:
K >> graph =
graph with properties:
Edges: [773×2 table]
Nodes: [773×0 table]
Which means I have 773 edges and each edge has 2 vertices. The graph edges look like this:
EndNodes Weight
__________ ______
1 2 1
1 53 1.4142
2 3 1
3 4 1
4 5 1
Now, at the end of the graph creation, I have other helper functions that help me create a diameters table with points that have been inferred on the binary image between the vessel walls. So, for each graph point the algorithm tries to look for walls and once found it saves the coordinates and other values in a table.
This is how the table gets created and how it looks like:
diam_tab = table();
for i = 1:n_line % for all the lines detected
row = cell(1,7);
row{1} = dt(i,:); % the diameter measured
row{2} = t; % the time dimension
row{3} = fs; % the frame sampling rate
row{4} = squeeze(permute(w1_t(i,:,:), [1, 3, 2])); % The value coordiantes of the first wall
row{5} = squeeze(permute(w2_t(i,:,:), [1, 3, 2])); % The value coordinates of the second wall
row{6} = line_type(i); % just a string, not relevant
row{7} = util.make_uuid(); % an UUID attached
diam_tab = [diam_tab; row];
end
And finally look like this:
y x fs z1 z2 type UUID
______________ ______________ ______ ________________ ________________ ________ ________________________________________
1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘6ada1ae1-00f8-4d9b-aa7a-80c7be26aaa1’}
1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘b8da617c-f55f-418c-88dc-5862c968a637’}
Now, what I want to do is, modify this table so that it doesn’t take all of the 773 rows but instead only like an average of the diameters over a certain segment of the graph. Let’s suppose say that the graph has a Y shape, I would like to obtain, every lets say 10 points an average diameter of that section.
Then, finally, the diam_tab table will not have 773 rows, but only the ones left after averaging over several sections of the graph, let’s say for a graph length of 100 the result would be 100 rows, but I want to get instead the average of the graph at sections of length for ex 10, which would leave me with 10 rows.
And finally, the diam_table would be updated to reflect these values, or at the very least replaced by a similar functioning table.
So far, this is what I turned up with in my code, which isn’t exactly working well as it seems to only get center points between two nodes and then breaks when I attach the created structure to the graph.
function diameters_table = segment_vessel_table(ts, diam_tab)
graph = ts.load_var(‘center_line’).graph;
[y, x] = find(ts.load_var(‘binary_image’));
node_coordinates = [x, y];
n_vessels = height(diam_tab);
midpoints = zeros(n_vessels, 2);
n_samples_graph = 5;
for i = 1:n_vessels
z1 = diam_tab.z1{i};
z2 = diam_tab.z2{i};
mids = (z1 + z2) / 2;
midpoints(i, 🙂 = mean(mids, 2);
end
idx = round(linspace(1, size(z1, 2), n_samples_graph));
sample_points = mean((z1(:, idx) + z2(:, idx)) / 2, 2);
graph = calculate_branch_centers(graph, node_coordinates);
distances = pdist2(midpoints, graph.Nodes.branch_centers);
[~, branch_idx] = min(distances, [], 2);
diam_tab.branch_id = branch_idx;
diameters_table = diam_tab;
end
function graph = calculate_branch_centers(graph, node_coordinates)
n_edges = height(graph.Edges);
branch_centers = zeros(n_edges, 2);
for i = 1:n_edges
node1 = graph.Edges.EndNodes(i, 1);
node2 = graph.Edges.EndNodes(i, 2);
p1 = node_coordinates(node1, :);
p2 = node_coordinates(node2, :);
branch_centers(i, 🙂 = (p1 + p2) / 2;
end
graph.branch_centers = branch_centers; % it breaks here
end
function [xs, x_names, fs] = load_vars(trial)
ts = trial.load_var("tseries");
diam_tab = ts.load_var("diameters");
diam_tab = segment_vessel_table(ts, diam_tab);
dt = diam_tab{:, "y"};
t = diam_tab.x;
t = t(1,:);
xs = TimeSeries(t, dt’);
x_names = "diameter";
% Freq bands is another part that works and not shown atm
for i = 1:size(freq_bands,1)
name = freq_bands{i,1};
xs = [xs; bands.(name)];
x_names = [x_names; name];
end
end I have a graph structure that is formed after binarizing an image of blood vessels and obtaining the skeleton, then creating a graph structure. The graph looks like this:
K >> graph =
graph with properties:
Edges: [773×2 table]
Nodes: [773×0 table]
Which means I have 773 edges and each edge has 2 vertices. The graph edges look like this:
EndNodes Weight
__________ ______
1 2 1
1 53 1.4142
2 3 1
3 4 1
4 5 1
Now, at the end of the graph creation, I have other helper functions that help me create a diameters table with points that have been inferred on the binary image between the vessel walls. So, for each graph point the algorithm tries to look for walls and once found it saves the coordinates and other values in a table.
This is how the table gets created and how it looks like:
diam_tab = table();
for i = 1:n_line % for all the lines detected
row = cell(1,7);
row{1} = dt(i,:); % the diameter measured
row{2} = t; % the time dimension
row{3} = fs; % the frame sampling rate
row{4} = squeeze(permute(w1_t(i,:,:), [1, 3, 2])); % The value coordiantes of the first wall
row{5} = squeeze(permute(w2_t(i,:,:), [1, 3, 2])); % The value coordinates of the second wall
row{6} = line_type(i); % just a string, not relevant
row{7} = util.make_uuid(); % an UUID attached
diam_tab = [diam_tab; row];
end
And finally look like this:
y x fs z1 z2 type UUID
______________ ______________ ______ ________________ ________________ ________ ________________________________________
1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘6ada1ae1-00f8-4d9b-aa7a-80c7be26aaa1’}
1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘b8da617c-f55f-418c-88dc-5862c968a637’}
Now, what I want to do is, modify this table so that it doesn’t take all of the 773 rows but instead only like an average of the diameters over a certain segment of the graph. Let’s suppose say that the graph has a Y shape, I would like to obtain, every lets say 10 points an average diameter of that section.
Then, finally, the diam_tab table will not have 773 rows, but only the ones left after averaging over several sections of the graph, let’s say for a graph length of 100 the result would be 100 rows, but I want to get instead the average of the graph at sections of length for ex 10, which would leave me with 10 rows.
And finally, the diam_table would be updated to reflect these values, or at the very least replaced by a similar functioning table.
So far, this is what I turned up with in my code, which isn’t exactly working well as it seems to only get center points between two nodes and then breaks when I attach the created structure to the graph.
function diameters_table = segment_vessel_table(ts, diam_tab)
graph = ts.load_var(‘center_line’).graph;
[y, x] = find(ts.load_var(‘binary_image’));
node_coordinates = [x, y];
n_vessels = height(diam_tab);
midpoints = zeros(n_vessels, 2);
n_samples_graph = 5;
for i = 1:n_vessels
z1 = diam_tab.z1{i};
z2 = diam_tab.z2{i};
mids = (z1 + z2) / 2;
midpoints(i, 🙂 = mean(mids, 2);
end
idx = round(linspace(1, size(z1, 2), n_samples_graph));
sample_points = mean((z1(:, idx) + z2(:, idx)) / 2, 2);
graph = calculate_branch_centers(graph, node_coordinates);
distances = pdist2(midpoints, graph.Nodes.branch_centers);
[~, branch_idx] = min(distances, [], 2);
diam_tab.branch_id = branch_idx;
diameters_table = diam_tab;
end
function graph = calculate_branch_centers(graph, node_coordinates)
n_edges = height(graph.Edges);
branch_centers = zeros(n_edges, 2);
for i = 1:n_edges
node1 = graph.Edges.EndNodes(i, 1);
node2 = graph.Edges.EndNodes(i, 2);
p1 = node_coordinates(node1, :);
p2 = node_coordinates(node2, :);
branch_centers(i, 🙂 = (p1 + p2) / 2;
end
graph.branch_centers = branch_centers; % it breaks here
end
function [xs, x_names, fs] = load_vars(trial)
ts = trial.load_var("tseries");
diam_tab = ts.load_var("diameters");
diam_tab = segment_vessel_table(ts, diam_tab);
dt = diam_tab{:, "y"};
t = diam_tab.x;
t = t(1,:);
xs = TimeSeries(t, dt’);
x_names = "diameter";
% Freq bands is another part that works and not shown atm
for i = 1:size(freq_bands,1)
name = freq_bands{i,1};
xs = [xs; bands.(name)];
x_names = [x_names; name];
end
end graph, table, handles, image processing MATLAB Answers — New Questions
How do I determine if a column header exists in a table?
I am performing a readtable() command. Sometimes the table contains a column called "x"; sometimes it is called "y". How would you determine if one column exists or not. I looked through the is* functions but did not see anything that I could use in an if statement.I am performing a readtable() command. Sometimes the table contains a column called "x"; sometimes it is called "y". How would you determine if one column exists or not. I looked through the is* functions but did not see anything that I could use in an if statement. I am performing a readtable() command. Sometimes the table contains a column called "x"; sometimes it is called "y". How would you determine if one column exists or not. I looked through the is* functions but did not see anything that I could use in an if statement. existing column MATLAB Answers — New Questions
My 6×6 symbolic Jacobian matrix is massive, and matlabFunction( ) is having trouble writing the corresponding numerical function file.
Hi there!
I currently have a 6×6 symoblic Jacobian using the Symbolic Math Toolbox. It is massive, when I take a peek at it using the Command Window. I then used matlabFunction( ) to convert this symbolic Jacobian to a numerical function. If I use matlabFunction’s default optimize = true, the numerical function file is about 8,000 lines of code, and I get a message there that says the code is too complex to analyze, and that I should reduce the number of operations in my code. On the other hand, if I use matlabFunction’s optimize = false option, the numerical function file is 59,506 lines of code, and I get a message there that says the file is too large. I then tried passing to matlabFunction( ), "Sparse", true, to try to get a sparse numerical Jacobian function file, but I still get the message in the numerical file that the code is too complex to analyze.
What can I do from here?
My goal is to successfully get a numerical Jacobian function file, then evaluate it to get a numerical Jacobian, and then find its eigenvalues using eig( ).
Thanks in advance,Hi there!
I currently have a 6×6 symoblic Jacobian using the Symbolic Math Toolbox. It is massive, when I take a peek at it using the Command Window. I then used matlabFunction( ) to convert this symbolic Jacobian to a numerical function. If I use matlabFunction’s default optimize = true, the numerical function file is about 8,000 lines of code, and I get a message there that says the code is too complex to analyze, and that I should reduce the number of operations in my code. On the other hand, if I use matlabFunction’s optimize = false option, the numerical function file is 59,506 lines of code, and I get a message there that says the file is too large. I then tried passing to matlabFunction( ), "Sparse", true, to try to get a sparse numerical Jacobian function file, but I still get the message in the numerical file that the code is too complex to analyze.
What can I do from here?
My goal is to successfully get a numerical Jacobian function file, then evaluate it to get a numerical Jacobian, and then find its eigenvalues using eig( ).
Thanks in advance, Hi there!
I currently have a 6×6 symoblic Jacobian using the Symbolic Math Toolbox. It is massive, when I take a peek at it using the Command Window. I then used matlabFunction( ) to convert this symbolic Jacobian to a numerical function. If I use matlabFunction’s default optimize = true, the numerical function file is about 8,000 lines of code, and I get a message there that says the code is too complex to analyze, and that I should reduce the number of operations in my code. On the other hand, if I use matlabFunction’s optimize = false option, the numerical function file is 59,506 lines of code, and I get a message there that says the file is too large. I then tried passing to matlabFunction( ), "Sparse", true, to try to get a sparse numerical Jacobian function file, but I still get the message in the numerical file that the code is too complex to analyze.
What can I do from here?
My goal is to successfully get a numerical Jacobian function file, then evaluate it to get a numerical Jacobian, and then find its eigenvalues using eig( ).
Thanks in advance, jacobian symbolic numerical matlab MATLAB Answers — New Questions
Why do I receive the error regarding “polyspace.connector.Service” when using the report generator?
While trying report generation, the following error is thrown:
Location: null, user name: xxxxxxxxx,
id: xxx@xxxxxxx, print mode: false Polyspace Report Generator Loading results Error: matlab.internal.webservices.HTTPConnector/copyContentToByteArray (Line 373)
The server returned the status 503 with message "Service Unavailable" in response to the request to URL URL http://localhost:9254/metadata.
However, if I run the analysis and then generate a report, the following message is thrown:
error: polyspace.connector.Service/nGetPort (line 198)
No available ports found in the range 9093-10093
error: polyspace.connector.Service (line 88)
error: polyspace.connector.Query (line 37)
error: PolySpaceResult/Query (line 400)
error: PolySpaceResult/GetResultProperties (line 607)
error: PolySpaceResult/Initialise (line 471)
error: PolySpaceResult (line 103)
error: PolySpaceResultInterface (line 279)
error: polyspace_report_internal (line 174)
error: psrptgenprivate (line 19)
error: polyspace_report (line 7)
polyspace:pscore:noPortForConnectorError
**********************************************************
***
*** Report generation done
***
**********************************************************While trying report generation, the following error is thrown:
Location: null, user name: xxxxxxxxx,
id: xxx@xxxxxxx, print mode: false Polyspace Report Generator Loading results Error: matlab.internal.webservices.HTTPConnector/copyContentToByteArray (Line 373)
The server returned the status 503 with message "Service Unavailable" in response to the request to URL URL http://localhost:9254/metadata.
However, if I run the analysis and then generate a report, the following message is thrown:
error: polyspace.connector.Service/nGetPort (line 198)
No available ports found in the range 9093-10093
error: polyspace.connector.Service (line 88)
error: polyspace.connector.Query (line 37)
error: PolySpaceResult/Query (line 400)
error: PolySpaceResult/GetResultProperties (line 607)
error: PolySpaceResult/Initialise (line 471)
error: PolySpaceResult (line 103)
error: PolySpaceResultInterface (line 279)
error: polyspace_report_internal (line 174)
error: psrptgenprivate (line 19)
error: polyspace_report (line 7)
polyspace:pscore:noPortForConnectorError
**********************************************************
***
*** Report generation done
***
********************************************************** While trying report generation, the following error is thrown:
Location: null, user name: xxxxxxxxx,
id: xxx@xxxxxxx, print mode: false Polyspace Report Generator Loading results Error: matlab.internal.webservices.HTTPConnector/copyContentToByteArray (Line 373)
The server returned the status 503 with message "Service Unavailable" in response to the request to URL URL http://localhost:9254/metadata.
However, if I run the analysis and then generate a report, the following message is thrown:
error: polyspace.connector.Service/nGetPort (line 198)
No available ports found in the range 9093-10093
error: polyspace.connector.Service (line 88)
error: polyspace.connector.Query (line 37)
error: PolySpaceResult/Query (line 400)
error: PolySpaceResult/GetResultProperties (line 607)
error: PolySpaceResult/Initialise (line 471)
error: PolySpaceResult (line 103)
error: PolySpaceResultInterface (line 279)
error: polyspace_report_internal (line 174)
error: psrptgenprivate (line 19)
error: polyspace_report (line 7)
polyspace:pscore:noPortForConnectorError
**********************************************************
***
*** Report generation done
***
********************************************************** polyspace, connector, report, generator, firewall, antivirus MATLAB Answers — New Questions
How do I configure the default camera views in unreal engine co-simulation?
I am using the aerospace toolbox and passing vehicle dynamic state into unreal engine. Everything works great except the camera views in unreal engine editor. I am using Cesium ion which only renders tiles in the vicinity of the main camera fucrum. I have multiple camera views such as one looking down from the top of my rocket at the fins which does not render. The vehicle is relatively small and the default viewer camera angles are very far away from the vehicle. Is there a way to re-configure the default camera views or fix my problem with cesium rendering?I am using the aerospace toolbox and passing vehicle dynamic state into unreal engine. Everything works great except the camera views in unreal engine editor. I am using Cesium ion which only renders tiles in the vicinity of the main camera fucrum. I have multiple camera views such as one looking down from the top of my rocket at the fins which does not render. The vehicle is relatively small and the default viewer camera angles are very far away from the vehicle. Is there a way to re-configure the default camera views or fix my problem with cesium rendering? I am using the aerospace toolbox and passing vehicle dynamic state into unreal engine. Everything works great except the camera views in unreal engine editor. I am using Cesium ion which only renders tiles in the vicinity of the main camera fucrum. I have multiple camera views such as one looking down from the top of my rocket at the fins which does not render. The vehicle is relatively small and the default viewer camera angles are very far away from the vehicle. Is there a way to re-configure the default camera views or fix my problem with cesium rendering? unreal engine, cesium, aerospace toolbox, aerospace blockset, visualization, simulation, simulink MATLAB Answers — New Questions
exporting-to-excel-spreadsheets
Hello, I am trying to do what I feel is very basic task. I have numerous excel files. Parameter name across the top row, data point from row 2:xxxx.
What I want to be able to do is go through a number of files, grab the filenames, column x name for title, and say search for the highest poinit in that column, or calculate average of that column.
I’m struggling to really understand how to do this, I’m no programmer, that is 100% certain. If I could get something put together to do this I feel that it could help to me process a majority of the files I work with, not doing this exact task, but very similar. I’ve not had the best of luck finding responses by searching forums, etc to do this for people who don’t understand programming, so I’m looking for an idiots guide to how to do basic tasks like this with matlab. If anyone has something they think would help, please post up.
Thanks!Hello, I am trying to do what I feel is very basic task. I have numerous excel files. Parameter name across the top row, data point from row 2:xxxx.
What I want to be able to do is go through a number of files, grab the filenames, column x name for title, and say search for the highest poinit in that column, or calculate average of that column.
I’m struggling to really understand how to do this, I’m no programmer, that is 100% certain. If I could get something put together to do this I feel that it could help to me process a majority of the files I work with, not doing this exact task, but very similar. I’ve not had the best of luck finding responses by searching forums, etc to do this for people who don’t understand programming, so I’m looking for an idiots guide to how to do basic tasks like this with matlab. If anyone has something they think would help, please post up.
Thanks! Hello, I am trying to do what I feel is very basic task. I have numerous excel files. Parameter name across the top row, data point from row 2:xxxx.
What I want to be able to do is go through a number of files, grab the filenames, column x name for title, and say search for the highest poinit in that column, or calculate average of that column.
I’m struggling to really understand how to do this, I’m no programmer, that is 100% certain. If I could get something put together to do this I feel that it could help to me process a majority of the files I work with, not doing this exact task, but very similar. I’ve not had the best of luck finding responses by searching forums, etc to do this for people who don’t understand programming, so I’m looking for an idiots guide to how to do basic tasks like this with matlab. If anyone has something they think would help, please post up.
Thanks! excel, export, basic MATLAB Answers — New Questions
Simulink windows turn yellow almost always.
This is an example. This is data inspector in simulink as an example, other windows mostly do the same. I have been looking on the internet for a solution but found nothing. This is on a new laptop and this issue does not occur on any other program I use. anyone having a similar issue?This is an example. This is data inspector in simulink as an example, other windows mostly do the same. I have been looking on the internet for a solution but found nothing. This is on a new laptop and this issue does not occur on any other program I use. anyone having a similar issue? This is an example. This is data inspector in simulink as an example, other windows mostly do the same. I have been looking on the internet for a solution but found nothing. This is on a new laptop and this issue does not occur on any other program I use. anyone having a similar issue? simulink gui MATLAB Answers — New Questions
Inverting an 8×8 symbolic matrix
I am trying to invert an 8×8 symbolic matrix with 32 symbolic variables in total. However, when running the standard inversion methods with inv() or mldivide(), the program takes a lot of time and ended up crashing all the times I tried to invert this matrix. I tried some workarounds, such as a recursive inversion algorithm using Schur decomposition and other ways of using the fact that I know that the matrix is symmetric, but to no avail. The function has a lot of sines and cosines of these variables, which might also be a problem.
I am looking for ways I can get this matrix inverted, or any further suggestion on how to tackle this problem.
Thanks in advance.
For context: the matrix I am trying to invert is the inertia matrix for a tiltrotor UAV. the 32 parameters consist of 6 state variables and 26 model parameters. My goal with this is to get an analytic expression for the system equations of motion:
With that expression, I intend to obtain an analytic linearization of the system in order to get a linear model , where . With these analytical expressions should be able to easily get A, B matrices for different values of the system parameters and formulate robust linear controllers with polytopic uncertainty.I am trying to invert an 8×8 symbolic matrix with 32 symbolic variables in total. However, when running the standard inversion methods with inv() or mldivide(), the program takes a lot of time and ended up crashing all the times I tried to invert this matrix. I tried some workarounds, such as a recursive inversion algorithm using Schur decomposition and other ways of using the fact that I know that the matrix is symmetric, but to no avail. The function has a lot of sines and cosines of these variables, which might also be a problem.
I am looking for ways I can get this matrix inverted, or any further suggestion on how to tackle this problem.
Thanks in advance.
For context: the matrix I am trying to invert is the inertia matrix for a tiltrotor UAV. the 32 parameters consist of 6 state variables and 26 model parameters. My goal with this is to get an analytic expression for the system equations of motion:
With that expression, I intend to obtain an analytic linearization of the system in order to get a linear model , where . With these analytical expressions should be able to easily get A, B matrices for different values of the system parameters and formulate robust linear controllers with polytopic uncertainty. I am trying to invert an 8×8 symbolic matrix with 32 symbolic variables in total. However, when running the standard inversion methods with inv() or mldivide(), the program takes a lot of time and ended up crashing all the times I tried to invert this matrix. I tried some workarounds, such as a recursive inversion algorithm using Schur decomposition and other ways of using the fact that I know that the matrix is symmetric, but to no avail. The function has a lot of sines and cosines of these variables, which might also be a problem.
I am looking for ways I can get this matrix inverted, or any further suggestion on how to tackle this problem.
Thanks in advance.
For context: the matrix I am trying to invert is the inertia matrix for a tiltrotor UAV. the 32 parameters consist of 6 state variables and 26 model parameters. My goal with this is to get an analytic expression for the system equations of motion:
With that expression, I intend to obtain an analytic linearization of the system in order to get a linear model , where . With these analytical expressions should be able to easily get A, B matrices for different values of the system parameters and formulate robust linear controllers with polytopic uncertainty. symbolic, matrix, inverse MATLAB Answers — New Questions
Solve DAEs using IDASolve function of SUNDIALS 2.6.2 version
I am trying to solve the system of differential algebraic equations which are used to model the IEEE 9 bus system. The differential equations determines the dynamic behaviour of the generators while the algebraic equations consists of the stator and the network (power flow) equations.
I have attached a MATLAB code in which the function "fun_DAE" gives out all of the equations in the form of a column vectors. ‘ F_D ‘ gives the 21 differential equations (7 for each generator), ‘ F_SA ‘ gives 18 network equations (real and reactive power balances for 9 buses) and ‘ F_SA’ gives the 6 stator equations (2 for each generator). ‘ F_SA’ and ‘ F_N ‘ constitutes the algebraic constraints.
the differential variables are for each generator. The initial values of this state variables are calculated and stored as matrix.
I need some help in using the IDAInit, IDASetOptions and IDASolve functions or any other relevant functions to be used to get a solution.
Thank You.I am trying to solve the system of differential algebraic equations which are used to model the IEEE 9 bus system. The differential equations determines the dynamic behaviour of the generators while the algebraic equations consists of the stator and the network (power flow) equations.
I have attached a MATLAB code in which the function "fun_DAE" gives out all of the equations in the form of a column vectors. ‘ F_D ‘ gives the 21 differential equations (7 for each generator), ‘ F_SA ‘ gives 18 network equations (real and reactive power balances for 9 buses) and ‘ F_SA’ gives the 6 stator equations (2 for each generator). ‘ F_SA’ and ‘ F_N ‘ constitutes the algebraic constraints.
the differential variables are for each generator. The initial values of this state variables are calculated and stored as matrix.
I need some help in using the IDAInit, IDASetOptions and IDASolve functions or any other relevant functions to be used to get a solution.
Thank You. I am trying to solve the system of differential algebraic equations which are used to model the IEEE 9 bus system. The differential equations determines the dynamic behaviour of the generators while the algebraic equations consists of the stator and the network (power flow) equations.
I have attached a MATLAB code in which the function "fun_DAE" gives out all of the equations in the form of a column vectors. ‘ F_D ‘ gives the 21 differential equations (7 for each generator), ‘ F_SA ‘ gives 18 network equations (real and reactive power balances for 9 buses) and ‘ F_SA’ gives the 6 stator equations (2 for each generator). ‘ F_SA’ and ‘ F_N ‘ constitutes the algebraic constraints.
the differential variables are for each generator. The initial values of this state variables are calculated and stored as matrix.
I need some help in using the IDAInit, IDASetOptions and IDASolve functions or any other relevant functions to be used to get a solution.
Thank You. sundials, ode MATLAB Answers — New Questions
MATLAB’s volshow command displays gray pixels as the inverse RGB color of any colored pixels also present in the dataset
I have a segmented 3D image dataset that I am trying to visualize. Because there are two segmented phases, I am exploring different colors for each phase to make them stand out from each other. In particular, I would like one of the phases to be blue (RGB [0, 0, 255]) and the other phase to be gray (RGB [128, 128, 128]). I have created a 4D uint8 dataset of the segmented images to allow for this, and when I load the image stack in MATLAB’s sliceViewer everything looks correct. However, when I then load the same dataset in MATLAB’s volshow, it colors the gray pixels yellow while the blue pixels remain blue. See pictures below:
SliceViewer Image Showing Gray = Gray with Blue Colored Phase
Volshow Image Showing Gray = Yellow with Blue Colored Phase
I thought that perhaps there was an issue with the lighting option being colored and casting a color onto gray pixels, but I have the lighting option turned off. I then thought that perhaps there was an issue with grayscale pixels in volshow, but when I convert the gray pixels to white (RGB [255, 255, 255]) they appear white in volshow. The same exact effect is achieved if the blue pixels are reduced in intensity to RGB [0, 0, 128] while leaving the gray pixels as RGB [128, 128, 128] (the sliceViewer will look different showing a darker blue but the volshow looks identical to the picture below with a bright blue and white-colored gray pixels). See pictures below:
SliceViewer Image Showing White = White with Blue Colored Phase
Volshow Image Showing White = White with Blue Colored Phase
I then explored other colors to see if there is a specific issue with the blue/gray combination and found interesting results. When I converted the blue pixels to red (RGB [255, 0, 0]), the gray pixels remained gray in sliceViewer but now display as cyan in volshow. See pictures below:
SliceViewer Image Showing Gray = Gray with Red Colored Phase
Volshow Image Showing Gray = Cyan with Red Colored Phase
The blue/gray and red/gray tests demonstrate that volshow will replace gray pixels with the inverse RGB color of any colored pixels in the dataset (yellow is the opposite RGB of blue ([255, 255, 0] vs. [0, 0, 255]) and cyan is the opposite RGB of red ([0, 255, 255] vs. [255, 0, 0])). However, the yellow and cyan colors do not appear to be their full intensity versions ([255, 255, 0] for yellow and [0, 255, 255] for cyan) and they may have some degree of their typically absent color present, but I cannot tell as these pixels do not actually have these intensity values in the image data so I cannot tell to what the true color is that they are creating. Thus, I cannot determine to what degree the opposite colors are added and the main color is substracted from the gray pixels.
I then tried substituting the colored phase for white to see if that maintained the gray pixels, and this worked (note that it may be difficult to see the difference between white and gray in the volShow, but I turned the volume around, zoomed in, and was able to verify that this was the case). See pictures below:
SliceViewer Image Showing Gray = Gray with White Colored Phase
Volshow Image Showing Gray = Gray with White Colored Phase
I was then curious as to what would happen to the gray pixels if I added a third, differently-colored phase. So, I added a red strip down one side of the blue/gray volume. Now, the gray pixels turned green (again, to what degree the blue and red intensities were added vs. substracted and how much of the green intensity was added, I cannot know). See pictures below:
SliceViewer Image Showing Gray = Gray with Blue and Red Colored Phases
Volshow Image Showing Gray = Green with Blue and Red Colored Phases
I don’t know if I am doing something wrong, so I have provided a snippet of code that will re-create all of this as well as a google drive link (the file is >5 MB so I can’t upload it) to the dataset I am using to investigate this. The code will let you select the data and automatically load it for you and then produce all of the images I have included here in there sliceViewer and volshow formats so that you can explore them). Here is the link to the dataset and here is the code:
%% Test Case %%
close all
clear
clc
% Select image file
fprintf(‘Select an image file.nn’)
[file_name, path_intro] = uigetfile(‘*.*’, ‘Select an image file’);
file_path = sprintf(‘%s%s’, path_intro, file_name);
% Import image message
clc
fprintf(‘Importing image stack…nn’)
% Create tiff
stack_tiff = Tiff(file_path);
% Determine number of images in stack
info = imfinfo(file_path);
no_slice = numel(info);
% Determine necessary tags from tiff
bits = getTag(stack_tiff, ‘BitsPerSample’);
long = getTag(stack_tiff, ‘ImageLength’);
wide = getTag(stack_tiff, ‘ImageWidth’);
samples = getTag(stack_tiff, ‘SamplesPerPixel’);
% Pre-allocate volume array
volume = zeros(long, wide, no_slice, samples, ‘uint8’);
% Import first image
volume(:, :, 1, 🙂 = read(stack_tiff);
% Import loop
for n = 2:no_slice
% Update current directory
nextDirectory(stack_tiff);
% Add current slice to volume
volume(:, :, n, 🙂 = read(stack_tiff);
end
% Close tiff
close(stack_tiff)
% Create transformation matrix
T = [1.31 0 0 0; 0 1.31 0 0; 0 0 1.31 0; 0 0 0 1];
tform = affinetform3d(T);
% Create viewer parameters structure
view_struct = struct;
% Populate viewer parameters structure
view_struct.BackgroundColor = [1 1 1];
view_struct.BackgroundGradient = ‘off’;
view_struct.Lighting = ‘off’;
% Load first slice viewer
clc
fprintf(‘Loading first slice viewer…nn’)
f1 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with Blue Colored Phase’);
sliceViewer(volume, parent = f1);
% Load first volume viewer
clc
fprintf(‘Loading first volume viewer…nn’)
uif1 = uifigure(‘Name’, ‘Gray = Yellow in Volume Viewer with Blue Colored Phase’);
viewer1 = viewer3d(view_struct, parent = uif1);
V1 = volshow(volume, ‘Transformation’, tform, parent = viewer1);
% Convert gray to white in second volume
clc
fprintf(‘Converting gray to white…nn’)
g2w_vol = volume;
g2w_vol(volume == 128) = 255;
% Load second slice viewer
clc
fprintf(‘Loading second slice viewer…nn’)
f2 = figure(‘Name’, ‘White = White in Slice Viewer with Blue Colored Phase’);
sliceViewer(g2w_vol, parent = f2);
% Load second volume viewer
clc
fprintf(‘Loading second volume viewer…nn’)
uif2 = uifigure(‘Name’, ‘White = White in Volume Viewer with Blue Colored Phase’);
viewer2 = viewer3d(view_struct, parent = uif2);
V2 = volshow(g2w_vol, ‘Transformation’, tform, parent = viewer2);
% Convert blue to red in third volume
clc
fprintf(‘Converting blue to red…nn’)
b2r_vol = volume;
b2r_vol(:, :, :, 1) = volume(:, :, :, 3);
b2r_vol(:, :, :, 3) = volume(:, :, :, 1);
% Load third slice viewer
clc
fprintf(‘Loading third slice viewer…nn’)
f3 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with Red Colored Phase’);
sliceViewer(b2r_vol, parent = f3);
% Load third volume viewer
clc
fprintf(‘Loading third volume viewer…nn’)
uif3 = uifigure(‘Name’, ‘Gray = Cyan in Volume Viewer with Red Colored Phase’);
viewer3 = viewer3d(view_struct, parent = uif3);
V3 = volshow(b2r_vol, ‘Transformation’, tform, parent = viewer3);
% Convert blue to white in fourth volume
clc
fprintf(‘Converting blue to white…nn’)
b2w_vol = volume;
b2w_vol(:, :, :, 1) = volume(:, :, :, 3);
b2w_vol(:, :, :, 2) = volume(:, :, :, 3);
% Load fourth slice viewer
clc
fprintf(‘Loading fourth slice viewer…nn’)
f4 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with White Colored Phase’);
sliceViewer(b2w_vol, parent = f4);
% Load fourth volume viewer
clc
fprintf(‘Loading fourth volume viewer…nn’)
uif4 = uifigure(‘Name’, ‘Gray = Gray in Volume Viewer with White Colored Phase’);
viewer4 = viewer3d(view_struct, parent = uif4);
V4 = volshow(b2w_vol, ‘Transformation’, tform, parent = viewer4);
% Add red strip in fifth volume
clc
fprintf(‘Adding red strip…nn’)
br_vol = volume;
br_vol(:, 1:25, :, 1) = 255;
br_vol(:, 1:25, :, 2:3) = 0;
% Load fifth slice viewer
clc
fprintf(‘Loading fifth slice viewer…nn’)
f5 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with White Colored Phase’);
sliceViewer(br_vol, parent = f5);
% Load fifth volume viewer
clc
fprintf(‘Loading fifth volume viewer…nn’)
uif5 = uifigure(‘Name’, ‘Gray = Gray in Volume Viewer with White Colored Phase’);
viewer5 = viewer3d(view_struct, parent = uif5);
V5 = volshow(br_vol, ‘Transformation’, tform, parent = viewer5);
% End message
clc
fprintf(‘Finished!nn’)I have a segmented 3D image dataset that I am trying to visualize. Because there are two segmented phases, I am exploring different colors for each phase to make them stand out from each other. In particular, I would like one of the phases to be blue (RGB [0, 0, 255]) and the other phase to be gray (RGB [128, 128, 128]). I have created a 4D uint8 dataset of the segmented images to allow for this, and when I load the image stack in MATLAB’s sliceViewer everything looks correct. However, when I then load the same dataset in MATLAB’s volshow, it colors the gray pixels yellow while the blue pixels remain blue. See pictures below:
SliceViewer Image Showing Gray = Gray with Blue Colored Phase
Volshow Image Showing Gray = Yellow with Blue Colored Phase
I thought that perhaps there was an issue with the lighting option being colored and casting a color onto gray pixels, but I have the lighting option turned off. I then thought that perhaps there was an issue with grayscale pixels in volshow, but when I convert the gray pixels to white (RGB [255, 255, 255]) they appear white in volshow. The same exact effect is achieved if the blue pixels are reduced in intensity to RGB [0, 0, 128] while leaving the gray pixels as RGB [128, 128, 128] (the sliceViewer will look different showing a darker blue but the volshow looks identical to the picture below with a bright blue and white-colored gray pixels). See pictures below:
SliceViewer Image Showing White = White with Blue Colored Phase
Volshow Image Showing White = White with Blue Colored Phase
I then explored other colors to see if there is a specific issue with the blue/gray combination and found interesting results. When I converted the blue pixels to red (RGB [255, 0, 0]), the gray pixels remained gray in sliceViewer but now display as cyan in volshow. See pictures below:
SliceViewer Image Showing Gray = Gray with Red Colored Phase
Volshow Image Showing Gray = Cyan with Red Colored Phase
The blue/gray and red/gray tests demonstrate that volshow will replace gray pixels with the inverse RGB color of any colored pixels in the dataset (yellow is the opposite RGB of blue ([255, 255, 0] vs. [0, 0, 255]) and cyan is the opposite RGB of red ([0, 255, 255] vs. [255, 0, 0])). However, the yellow and cyan colors do not appear to be their full intensity versions ([255, 255, 0] for yellow and [0, 255, 255] for cyan) and they may have some degree of their typically absent color present, but I cannot tell as these pixels do not actually have these intensity values in the image data so I cannot tell to what the true color is that they are creating. Thus, I cannot determine to what degree the opposite colors are added and the main color is substracted from the gray pixels.
I then tried substituting the colored phase for white to see if that maintained the gray pixels, and this worked (note that it may be difficult to see the difference between white and gray in the volShow, but I turned the volume around, zoomed in, and was able to verify that this was the case). See pictures below:
SliceViewer Image Showing Gray = Gray with White Colored Phase
Volshow Image Showing Gray = Gray with White Colored Phase
I was then curious as to what would happen to the gray pixels if I added a third, differently-colored phase. So, I added a red strip down one side of the blue/gray volume. Now, the gray pixels turned green (again, to what degree the blue and red intensities were added vs. substracted and how much of the green intensity was added, I cannot know). See pictures below:
SliceViewer Image Showing Gray = Gray with Blue and Red Colored Phases
Volshow Image Showing Gray = Green with Blue and Red Colored Phases
I don’t know if I am doing something wrong, so I have provided a snippet of code that will re-create all of this as well as a google drive link (the file is >5 MB so I can’t upload it) to the dataset I am using to investigate this. The code will let you select the data and automatically load it for you and then produce all of the images I have included here in there sliceViewer and volshow formats so that you can explore them). Here is the link to the dataset and here is the code:
%% Test Case %%
close all
clear
clc
% Select image file
fprintf(‘Select an image file.nn’)
[file_name, path_intro] = uigetfile(‘*.*’, ‘Select an image file’);
file_path = sprintf(‘%s%s’, path_intro, file_name);
% Import image message
clc
fprintf(‘Importing image stack…nn’)
% Create tiff
stack_tiff = Tiff(file_path);
% Determine number of images in stack
info = imfinfo(file_path);
no_slice = numel(info);
% Determine necessary tags from tiff
bits = getTag(stack_tiff, ‘BitsPerSample’);
long = getTag(stack_tiff, ‘ImageLength’);
wide = getTag(stack_tiff, ‘ImageWidth’);
samples = getTag(stack_tiff, ‘SamplesPerPixel’);
% Pre-allocate volume array
volume = zeros(long, wide, no_slice, samples, ‘uint8’);
% Import first image
volume(:, :, 1, 🙂 = read(stack_tiff);
% Import loop
for n = 2:no_slice
% Update current directory
nextDirectory(stack_tiff);
% Add current slice to volume
volume(:, :, n, 🙂 = read(stack_tiff);
end
% Close tiff
close(stack_tiff)
% Create transformation matrix
T = [1.31 0 0 0; 0 1.31 0 0; 0 0 1.31 0; 0 0 0 1];
tform = affinetform3d(T);
% Create viewer parameters structure
view_struct = struct;
% Populate viewer parameters structure
view_struct.BackgroundColor = [1 1 1];
view_struct.BackgroundGradient = ‘off’;
view_struct.Lighting = ‘off’;
% Load first slice viewer
clc
fprintf(‘Loading first slice viewer…nn’)
f1 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with Blue Colored Phase’);
sliceViewer(volume, parent = f1);
% Load first volume viewer
clc
fprintf(‘Loading first volume viewer…nn’)
uif1 = uifigure(‘Name’, ‘Gray = Yellow in Volume Viewer with Blue Colored Phase’);
viewer1 = viewer3d(view_struct, parent = uif1);
V1 = volshow(volume, ‘Transformation’, tform, parent = viewer1);
% Convert gray to white in second volume
clc
fprintf(‘Converting gray to white…nn’)
g2w_vol = volume;
g2w_vol(volume == 128) = 255;
% Load second slice viewer
clc
fprintf(‘Loading second slice viewer…nn’)
f2 = figure(‘Name’, ‘White = White in Slice Viewer with Blue Colored Phase’);
sliceViewer(g2w_vol, parent = f2);
% Load second volume viewer
clc
fprintf(‘Loading second volume viewer…nn’)
uif2 = uifigure(‘Name’, ‘White = White in Volume Viewer with Blue Colored Phase’);
viewer2 = viewer3d(view_struct, parent = uif2);
V2 = volshow(g2w_vol, ‘Transformation’, tform, parent = viewer2);
% Convert blue to red in third volume
clc
fprintf(‘Converting blue to red…nn’)
b2r_vol = volume;
b2r_vol(:, :, :, 1) = volume(:, :, :, 3);
b2r_vol(:, :, :, 3) = volume(:, :, :, 1);
% Load third slice viewer
clc
fprintf(‘Loading third slice viewer…nn’)
f3 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with Red Colored Phase’);
sliceViewer(b2r_vol, parent = f3);
% Load third volume viewer
clc
fprintf(‘Loading third volume viewer…nn’)
uif3 = uifigure(‘Name’, ‘Gray = Cyan in Volume Viewer with Red Colored Phase’);
viewer3 = viewer3d(view_struct, parent = uif3);
V3 = volshow(b2r_vol, ‘Transformation’, tform, parent = viewer3);
% Convert blue to white in fourth volume
clc
fprintf(‘Converting blue to white…nn’)
b2w_vol = volume;
b2w_vol(:, :, :, 1) = volume(:, :, :, 3);
b2w_vol(:, :, :, 2) = volume(:, :, :, 3);
% Load fourth slice viewer
clc
fprintf(‘Loading fourth slice viewer…nn’)
f4 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with White Colored Phase’);
sliceViewer(b2w_vol, parent = f4);
% Load fourth volume viewer
clc
fprintf(‘Loading fourth volume viewer…nn’)
uif4 = uifigure(‘Name’, ‘Gray = Gray in Volume Viewer with White Colored Phase’);
viewer4 = viewer3d(view_struct, parent = uif4);
V4 = volshow(b2w_vol, ‘Transformation’, tform, parent = viewer4);
% Add red strip in fifth volume
clc
fprintf(‘Adding red strip…nn’)
br_vol = volume;
br_vol(:, 1:25, :, 1) = 255;
br_vol(:, 1:25, :, 2:3) = 0;
% Load fifth slice viewer
clc
fprintf(‘Loading fifth slice viewer…nn’)
f5 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with White Colored Phase’);
sliceViewer(br_vol, parent = f5);
% Load fifth volume viewer
clc
fprintf(‘Loading fifth volume viewer…nn’)
uif5 = uifigure(‘Name’, ‘Gray = Gray in Volume Viewer with White Colored Phase’);
viewer5 = viewer3d(view_struct, parent = uif5);
V5 = volshow(br_vol, ‘Transformation’, tform, parent = viewer5);
% End message
clc
fprintf(‘Finished!nn’) I have a segmented 3D image dataset that I am trying to visualize. Because there are two segmented phases, I am exploring different colors for each phase to make them stand out from each other. In particular, I would like one of the phases to be blue (RGB [0, 0, 255]) and the other phase to be gray (RGB [128, 128, 128]). I have created a 4D uint8 dataset of the segmented images to allow for this, and when I load the image stack in MATLAB’s sliceViewer everything looks correct. However, when I then load the same dataset in MATLAB’s volshow, it colors the gray pixels yellow while the blue pixels remain blue. See pictures below:
SliceViewer Image Showing Gray = Gray with Blue Colored Phase
Volshow Image Showing Gray = Yellow with Blue Colored Phase
I thought that perhaps there was an issue with the lighting option being colored and casting a color onto gray pixels, but I have the lighting option turned off. I then thought that perhaps there was an issue with grayscale pixels in volshow, but when I convert the gray pixels to white (RGB [255, 255, 255]) they appear white in volshow. The same exact effect is achieved if the blue pixels are reduced in intensity to RGB [0, 0, 128] while leaving the gray pixels as RGB [128, 128, 128] (the sliceViewer will look different showing a darker blue but the volshow looks identical to the picture below with a bright blue and white-colored gray pixels). See pictures below:
SliceViewer Image Showing White = White with Blue Colored Phase
Volshow Image Showing White = White with Blue Colored Phase
I then explored other colors to see if there is a specific issue with the blue/gray combination and found interesting results. When I converted the blue pixels to red (RGB [255, 0, 0]), the gray pixels remained gray in sliceViewer but now display as cyan in volshow. See pictures below:
SliceViewer Image Showing Gray = Gray with Red Colored Phase
Volshow Image Showing Gray = Cyan with Red Colored Phase
The blue/gray and red/gray tests demonstrate that volshow will replace gray pixels with the inverse RGB color of any colored pixels in the dataset (yellow is the opposite RGB of blue ([255, 255, 0] vs. [0, 0, 255]) and cyan is the opposite RGB of red ([0, 255, 255] vs. [255, 0, 0])). However, the yellow and cyan colors do not appear to be their full intensity versions ([255, 255, 0] for yellow and [0, 255, 255] for cyan) and they may have some degree of their typically absent color present, but I cannot tell as these pixels do not actually have these intensity values in the image data so I cannot tell to what the true color is that they are creating. Thus, I cannot determine to what degree the opposite colors are added and the main color is substracted from the gray pixels.
I then tried substituting the colored phase for white to see if that maintained the gray pixels, and this worked (note that it may be difficult to see the difference between white and gray in the volShow, but I turned the volume around, zoomed in, and was able to verify that this was the case). See pictures below:
SliceViewer Image Showing Gray = Gray with White Colored Phase
Volshow Image Showing Gray = Gray with White Colored Phase
I was then curious as to what would happen to the gray pixels if I added a third, differently-colored phase. So, I added a red strip down one side of the blue/gray volume. Now, the gray pixels turned green (again, to what degree the blue and red intensities were added vs. substracted and how much of the green intensity was added, I cannot know). See pictures below:
SliceViewer Image Showing Gray = Gray with Blue and Red Colored Phases
Volshow Image Showing Gray = Green with Blue and Red Colored Phases
I don’t know if I am doing something wrong, so I have provided a snippet of code that will re-create all of this as well as a google drive link (the file is >5 MB so I can’t upload it) to the dataset I am using to investigate this. The code will let you select the data and automatically load it for you and then produce all of the images I have included here in there sliceViewer and volshow formats so that you can explore them). Here is the link to the dataset and here is the code:
%% Test Case %%
close all
clear
clc
% Select image file
fprintf(‘Select an image file.nn’)
[file_name, path_intro] = uigetfile(‘*.*’, ‘Select an image file’);
file_path = sprintf(‘%s%s’, path_intro, file_name);
% Import image message
clc
fprintf(‘Importing image stack…nn’)
% Create tiff
stack_tiff = Tiff(file_path);
% Determine number of images in stack
info = imfinfo(file_path);
no_slice = numel(info);
% Determine necessary tags from tiff
bits = getTag(stack_tiff, ‘BitsPerSample’);
long = getTag(stack_tiff, ‘ImageLength’);
wide = getTag(stack_tiff, ‘ImageWidth’);
samples = getTag(stack_tiff, ‘SamplesPerPixel’);
% Pre-allocate volume array
volume = zeros(long, wide, no_slice, samples, ‘uint8’);
% Import first image
volume(:, :, 1, 🙂 = read(stack_tiff);
% Import loop
for n = 2:no_slice
% Update current directory
nextDirectory(stack_tiff);
% Add current slice to volume
volume(:, :, n, 🙂 = read(stack_tiff);
end
% Close tiff
close(stack_tiff)
% Create transformation matrix
T = [1.31 0 0 0; 0 1.31 0 0; 0 0 1.31 0; 0 0 0 1];
tform = affinetform3d(T);
% Create viewer parameters structure
view_struct = struct;
% Populate viewer parameters structure
view_struct.BackgroundColor = [1 1 1];
view_struct.BackgroundGradient = ‘off’;
view_struct.Lighting = ‘off’;
% Load first slice viewer
clc
fprintf(‘Loading first slice viewer…nn’)
f1 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with Blue Colored Phase’);
sliceViewer(volume, parent = f1);
% Load first volume viewer
clc
fprintf(‘Loading first volume viewer…nn’)
uif1 = uifigure(‘Name’, ‘Gray = Yellow in Volume Viewer with Blue Colored Phase’);
viewer1 = viewer3d(view_struct, parent = uif1);
V1 = volshow(volume, ‘Transformation’, tform, parent = viewer1);
% Convert gray to white in second volume
clc
fprintf(‘Converting gray to white…nn’)
g2w_vol = volume;
g2w_vol(volume == 128) = 255;
% Load second slice viewer
clc
fprintf(‘Loading second slice viewer…nn’)
f2 = figure(‘Name’, ‘White = White in Slice Viewer with Blue Colored Phase’);
sliceViewer(g2w_vol, parent = f2);
% Load second volume viewer
clc
fprintf(‘Loading second volume viewer…nn’)
uif2 = uifigure(‘Name’, ‘White = White in Volume Viewer with Blue Colored Phase’);
viewer2 = viewer3d(view_struct, parent = uif2);
V2 = volshow(g2w_vol, ‘Transformation’, tform, parent = viewer2);
% Convert blue to red in third volume
clc
fprintf(‘Converting blue to red…nn’)
b2r_vol = volume;
b2r_vol(:, :, :, 1) = volume(:, :, :, 3);
b2r_vol(:, :, :, 3) = volume(:, :, :, 1);
% Load third slice viewer
clc
fprintf(‘Loading third slice viewer…nn’)
f3 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with Red Colored Phase’);
sliceViewer(b2r_vol, parent = f3);
% Load third volume viewer
clc
fprintf(‘Loading third volume viewer…nn’)
uif3 = uifigure(‘Name’, ‘Gray = Cyan in Volume Viewer with Red Colored Phase’);
viewer3 = viewer3d(view_struct, parent = uif3);
V3 = volshow(b2r_vol, ‘Transformation’, tform, parent = viewer3);
% Convert blue to white in fourth volume
clc
fprintf(‘Converting blue to white…nn’)
b2w_vol = volume;
b2w_vol(:, :, :, 1) = volume(:, :, :, 3);
b2w_vol(:, :, :, 2) = volume(:, :, :, 3);
% Load fourth slice viewer
clc
fprintf(‘Loading fourth slice viewer…nn’)
f4 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with White Colored Phase’);
sliceViewer(b2w_vol, parent = f4);
% Load fourth volume viewer
clc
fprintf(‘Loading fourth volume viewer…nn’)
uif4 = uifigure(‘Name’, ‘Gray = Gray in Volume Viewer with White Colored Phase’);
viewer4 = viewer3d(view_struct, parent = uif4);
V4 = volshow(b2w_vol, ‘Transformation’, tform, parent = viewer4);
% Add red strip in fifth volume
clc
fprintf(‘Adding red strip…nn’)
br_vol = volume;
br_vol(:, 1:25, :, 1) = 255;
br_vol(:, 1:25, :, 2:3) = 0;
% Load fifth slice viewer
clc
fprintf(‘Loading fifth slice viewer…nn’)
f5 = figure(‘Name’, ‘Gray = Gray in Slice Viewer with White Colored Phase’);
sliceViewer(br_vol, parent = f5);
% Load fifth volume viewer
clc
fprintf(‘Loading fifth volume viewer…nn’)
uif5 = uifigure(‘Name’, ‘Gray = Gray in Volume Viewer with White Colored Phase’);
viewer5 = viewer3d(view_struct, parent = uif5);
V5 = volshow(br_vol, ‘Transformation’, tform, parent = viewer5);
% End message
clc
fprintf(‘Finished!nn’) volshow, image processing, image segmentation MATLAB Answers — New Questions
We have tetrahedra mesh we went to extract a sphere from this mesh and adabting the mesh
We do this code, but we found a problem in the output tri
fid = fopen(‘nodes10.dat’);
data = fscanf(fid, ‘%g %g %g’, [3, Inf]);
A = data’;
fclose(fid);
A;
n=size(A);
kk=n(1);
R=1.5;
MM=zeros(kk,1);
for k=1:kk
MM(k)=0;
for i=1:3
MM(k)= MM(k)+ A(k,i)*A(k,i);
end
MM(k)=sqrt(MM(k));
end
M = A(MM >R,:);
[x1,y1,z1] = sphere(1);
Psphere = [R*x1(:) R*y1(:) R*z1(:)];
Psphere = unique(Psphere,’rows’);
P = [M;Psphere];
plot3(P(:,1),P(:,2),P(:,3),’.’)
shp= alphaShape(P(:,1),P(:,2),P(:,3),1);
plot(shp)
shp.Alpha = 2;
[tri,loc] = alphaTriangulation(shp);
fid = fopen(‘nodess.dat’,’w’);
fprintf(fid,’%it %it %in’,loc);
fclose(fid);
fid = fopen(‘tetreades.dat’,’w’);
fprintf(fid,’%it %it %it %in’,tri);
fclose(fid);
numtetrahedra = size(tri,1);
numnodes = size(loc);
% model = createpde;
% [gCube,mshC]=geometryFromMesh(model,loc’,tri’);
% %save (‘nodesn.txt’, ‘tri’)
% tri
% loc;
axis equalWe do this code, but we found a problem in the output tri
fid = fopen(‘nodes10.dat’);
data = fscanf(fid, ‘%g %g %g’, [3, Inf]);
A = data’;
fclose(fid);
A;
n=size(A);
kk=n(1);
R=1.5;
MM=zeros(kk,1);
for k=1:kk
MM(k)=0;
for i=1:3
MM(k)= MM(k)+ A(k,i)*A(k,i);
end
MM(k)=sqrt(MM(k));
end
M = A(MM >R,:);
[x1,y1,z1] = sphere(1);
Psphere = [R*x1(:) R*y1(:) R*z1(:)];
Psphere = unique(Psphere,’rows’);
P = [M;Psphere];
plot3(P(:,1),P(:,2),P(:,3),’.’)
shp= alphaShape(P(:,1),P(:,2),P(:,3),1);
plot(shp)
shp.Alpha = 2;
[tri,loc] = alphaTriangulation(shp);
fid = fopen(‘nodess.dat’,’w’);
fprintf(fid,’%it %it %in’,loc);
fclose(fid);
fid = fopen(‘tetreades.dat’,’w’);
fprintf(fid,’%it %it %it %in’,tri);
fclose(fid);
numtetrahedra = size(tri,1);
numnodes = size(loc);
% model = createpde;
% [gCube,mshC]=geometryFromMesh(model,loc’,tri’);
% %save (‘nodesn.txt’, ‘tri’)
% tri
% loc;
axis equal We do this code, but we found a problem in the output tri
fid = fopen(‘nodes10.dat’);
data = fscanf(fid, ‘%g %g %g’, [3, Inf]);
A = data’;
fclose(fid);
A;
n=size(A);
kk=n(1);
R=1.5;
MM=zeros(kk,1);
for k=1:kk
MM(k)=0;
for i=1:3
MM(k)= MM(k)+ A(k,i)*A(k,i);
end
MM(k)=sqrt(MM(k));
end
M = A(MM >R,:);
[x1,y1,z1] = sphere(1);
Psphere = [R*x1(:) R*y1(:) R*z1(:)];
Psphere = unique(Psphere,’rows’);
P = [M;Psphere];
plot3(P(:,1),P(:,2),P(:,3),’.’)
shp= alphaShape(P(:,1),P(:,2),P(:,3),1);
plot(shp)
shp.Alpha = 2;
[tri,loc] = alphaTriangulation(shp);
fid = fopen(‘nodess.dat’,’w’);
fprintf(fid,’%it %it %in’,loc);
fclose(fid);
fid = fopen(‘tetreades.dat’,’w’);
fprintf(fid,’%it %it %it %in’,tri);
fclose(fid);
numtetrahedra = size(tri,1);
numnodes = size(loc);
% model = createpde;
% [gCube,mshC]=geometryFromMesh(model,loc’,tri’);
% %save (‘nodesn.txt’, ‘tri’)
% tri
% loc;
axis equal sphere in tetrahedra MATLAB Answers — New Questions
Deploying CNN model on FPGA DE0 Nano Board
Hello,
I am planning to deploy a CNN on my FPGA DE0 Nano Board (Cyclone IV), which is a custom board not directly supported by MATLAB. I have made myself comfortable with HDL Coder in Simulink by working on FIL (FPGA-in-the-loop) workflow for video processing application and hence I am looking for a similar workflow using Simulink, HDL coder, etc.
Could you outline the exact steps to follow on how do I go about developing a simple model using Simulink (maybe start with SqueezeNet to begin with on Deep Network Designer), making it hardware compatible and the process to deploy it on my FPGA? The resources available online talk about IP core generation, etc, which are a bit confusing and overwhelming.
Thanks :)Hello,
I am planning to deploy a CNN on my FPGA DE0 Nano Board (Cyclone IV), which is a custom board not directly supported by MATLAB. I have made myself comfortable with HDL Coder in Simulink by working on FIL (FPGA-in-the-loop) workflow for video processing application and hence I am looking for a similar workflow using Simulink, HDL coder, etc.
Could you outline the exact steps to follow on how do I go about developing a simple model using Simulink (maybe start with SqueezeNet to begin with on Deep Network Designer), making it hardware compatible and the process to deploy it on my FPGA? The resources available online talk about IP core generation, etc, which are a bit confusing and overwhelming.
Thanks 🙂 Hello,
I am planning to deploy a CNN on my FPGA DE0 Nano Board (Cyclone IV), which is a custom board not directly supported by MATLAB. I have made myself comfortable with HDL Coder in Simulink by working on FIL (FPGA-in-the-loop) workflow for video processing application and hence I am looking for a similar workflow using Simulink, HDL coder, etc.
Could you outline the exact steps to follow on how do I go about developing a simple model using Simulink (maybe start with SqueezeNet to begin with on Deep Network Designer), making it hardware compatible and the process to deploy it on my FPGA? The resources available online talk about IP core generation, etc, which are a bit confusing and overwhelming.
Thanks 🙂 fpga, simulink, neural network, hdl, fpga in the loop MATLAB Answers — New Questions
How to generate 2-D Lookup Table data for a 3-Output Fuzzy Logic System
I want design a look up table for fuzzy logic which has 2 inputs and 3 outputs. I referred to help on mathworks however its for 2 inputs and 1 output. Please refer to attached image.
https://www.mathworks.com/help//releases/R2021a/fuzzy/implement-fuzzy-pid-controller-in-simulink-using-lookup-table.html#d123e17778
Please suggest a way to create look up table for fuzzy logic using 2 inputs and 3 outputs.I want design a look up table for fuzzy logic which has 2 inputs and 3 outputs. I referred to help on mathworks however its for 2 inputs and 1 output. Please refer to attached image.
https://www.mathworks.com/help//releases/R2021a/fuzzy/implement-fuzzy-pid-controller-in-simulink-using-lookup-table.html#d123e17778
Please suggest a way to create look up table for fuzzy logic using 2 inputs and 3 outputs. I want design a look up table for fuzzy logic which has 2 inputs and 3 outputs. I referred to help on mathworks however its for 2 inputs and 1 output. Please refer to attached image.
https://www.mathworks.com/help//releases/R2021a/fuzzy/implement-fuzzy-pid-controller-in-simulink-using-lookup-table.html#d123e17778
Please suggest a way to create look up table for fuzzy logic using 2 inputs and 3 outputs. simulink, matlab, fuzzy, fuzzy logic toolbox, lookuptables MATLAB Answers — New Questions
Transport Delay in Realtime simulation
Hello,
I set the simulation time to "inf" in order to be able to change the parameters during real-time.
However it seems that Transport Delay block is not working in this mode. When I switch to finite time, it is working, but then I can not change the parameters real-time.
How to solve this?
Thanks
M.Hello,
I set the simulation time to "inf" in order to be able to change the parameters during real-time.
However it seems that Transport Delay block is not working in this mode. When I switch to finite time, it is working, but then I can not change the parameters real-time.
How to solve this?
Thanks
M. Hello,
I set the simulation time to "inf" in order to be able to change the parameters during real-time.
However it seems that Transport Delay block is not working in this mode. When I switch to finite time, it is working, but then I can not change the parameters real-time.
How to solve this?
Thanks
M. delay, simulink, realtime MATLAB Answers — New Questions
How to send data between nodes in an iot network?
I have created a simulation environment for IoT network which consist of 10 nodes 1 edge node and 1 control center. I want to send data from nodes to the edge node.I have created a simulation environment for IoT network which consist of 10 nodes 1 edge node and 1 control center. I want to send data from nodes to the edge node. I have created a simulation environment for IoT network which consist of 10 nodes 1 edge node and 1 control center. I want to send data from nodes to the edge node. matlab, iot, nodes, iot network MATLAB Answers — New Questions
Is it possible to use the serialport object to connect exactly like Putty is able to?
I am using a MATLAB GUI app I wrote to connect via serial over USB to an Arduino. Unfortunately whenever I open the connection, the Arduino resets. This is expected behaviour, and there are hardware workarounds (including cutting the reset line, or using a 22uF cap like discussed here https://electronics.stackexchange.com/questions/24743/arduino-resetting-while-reconnecting-the-serial-terminal).
However, it IS also possible to prevent this behaviour by controlling the DTR line on the connection. For example, in Putty, if I select DSR/DTR mode, then the Arduino does not reset, so I know it is possible. I have not however been able to work out how to do it with MATLAB, and don’t know whether it is possible. I have explored the SerialPort object help, and am aware of the DTR option. However, I have exhausted all attempts at getting this to work and am now not sure whether it is even possible.
Has anyone ever done this or got it working?
Many thanks,I am using a MATLAB GUI app I wrote to connect via serial over USB to an Arduino. Unfortunately whenever I open the connection, the Arduino resets. This is expected behaviour, and there are hardware workarounds (including cutting the reset line, or using a 22uF cap like discussed here https://electronics.stackexchange.com/questions/24743/arduino-resetting-while-reconnecting-the-serial-terminal).
However, it IS also possible to prevent this behaviour by controlling the DTR line on the connection. For example, in Putty, if I select DSR/DTR mode, then the Arduino does not reset, so I know it is possible. I have not however been able to work out how to do it with MATLAB, and don’t know whether it is possible. I have explored the SerialPort object help, and am aware of the DTR option. However, I have exhausted all attempts at getting this to work and am now not sure whether it is even possible.
Has anyone ever done this or got it working?
Many thanks, I am using a MATLAB GUI app I wrote to connect via serial over USB to an Arduino. Unfortunately whenever I open the connection, the Arduino resets. This is expected behaviour, and there are hardware workarounds (including cutting the reset line, or using a 22uF cap like discussed here https://electronics.stackexchange.com/questions/24743/arduino-resetting-while-reconnecting-the-serial-terminal).
However, it IS also possible to prevent this behaviour by controlling the DTR line on the connection. For example, in Putty, if I select DSR/DTR mode, then the Arduino does not reset, so I know it is possible. I have not however been able to work out how to do it with MATLAB, and don’t know whether it is possible. I have explored the SerialPort object help, and am aware of the DTR option. However, I have exhausted all attempts at getting this to work and am now not sure whether it is even possible.
Has anyone ever done this or got it working?
Many thanks, matlab, serialport, arduino, dtr MATLAB Answers — New Questions
I am using the queue counter, I have put the queue counter in VISSIM GUI and saved & enabled it but while i am coding it in MATLAB the results are showing NaN, Why is it so
%Link Numbers
Link_Num_1=Link_i.ItemByKey(5);
Link_Num_2=Link_i.ItemByKey(7);
Link_Num_3=Link_i.ItemByKey(13);
Link_Num_4=Link_i.ItemByKey(23);
simulation_duration = 7200; % Total simulation time in seconds
interval = 1; % Collect queue length every 120 seconds
num_intervals = simulation_duration / interval; % Number of 120-second intervals (60)
% Initialize matrix for queue lengths (60 rows)
queue_lengths = zeros(num_intervals, 1);
% Get queue counter
queue_counters_1 = Link_Num_1.QueueCounters.GetAll;
qc1 = queue_counters_1{1}; % First queue counter
% Display queue counter info
disp([‘Number of queue counters: ‘, num2str(length(queue_counters_1))]);
disp([‘Queue Counter Object: ‘, class(qc1)]);
disp([‘Queue Counter Name: ‘, qc1.get(‘AttValue’, ‘Name’)]);
% Run simulation and collect queue length every 120 seconds
interval_idx = 0; % Counter for interval index
for t = 1:interval:simulation_duration
% Run simulation for 120 seconds
for step = 1:interval
sim.RunSingleStep;
end
% Increment interval index
interval_idx = interval_idx + 1;
% Get queue length
queue_length = qc1.get(‘AttValue’, ‘QLen(Current, Last)’);
if isnan(queue_length)
queue_length = 0; % Replace NaN with 0
end
queue_lengths(interval_idx, 1) = queue_length;
% Display queue length for this interval
disp([‘Time ‘, num2str(t), ‘s: Queue Length = ‘, num2str(queue_length)]);
end
disp(‘Queue Length collection complete.’);%Link Numbers
Link_Num_1=Link_i.ItemByKey(5);
Link_Num_2=Link_i.ItemByKey(7);
Link_Num_3=Link_i.ItemByKey(13);
Link_Num_4=Link_i.ItemByKey(23);
simulation_duration = 7200; % Total simulation time in seconds
interval = 1; % Collect queue length every 120 seconds
num_intervals = simulation_duration / interval; % Number of 120-second intervals (60)
% Initialize matrix for queue lengths (60 rows)
queue_lengths = zeros(num_intervals, 1);
% Get queue counter
queue_counters_1 = Link_Num_1.QueueCounters.GetAll;
qc1 = queue_counters_1{1}; % First queue counter
% Display queue counter info
disp([‘Number of queue counters: ‘, num2str(length(queue_counters_1))]);
disp([‘Queue Counter Object: ‘, class(qc1)]);
disp([‘Queue Counter Name: ‘, qc1.get(‘AttValue’, ‘Name’)]);
% Run simulation and collect queue length every 120 seconds
interval_idx = 0; % Counter for interval index
for t = 1:interval:simulation_duration
% Run simulation for 120 seconds
for step = 1:interval
sim.RunSingleStep;
end
% Increment interval index
interval_idx = interval_idx + 1;
% Get queue length
queue_length = qc1.get(‘AttValue’, ‘QLen(Current, Last)’);
if isnan(queue_length)
queue_length = 0; % Replace NaN with 0
end
queue_lengths(interval_idx, 1) = queue_length;
% Display queue length for this interval
disp([‘Time ‘, num2str(t), ‘s: Queue Length = ‘, num2str(queue_length)]);
end
disp(‘Queue Length collection complete.’); %Link Numbers
Link_Num_1=Link_i.ItemByKey(5);
Link_Num_2=Link_i.ItemByKey(7);
Link_Num_3=Link_i.ItemByKey(13);
Link_Num_4=Link_i.ItemByKey(23);
simulation_duration = 7200; % Total simulation time in seconds
interval = 1; % Collect queue length every 120 seconds
num_intervals = simulation_duration / interval; % Number of 120-second intervals (60)
% Initialize matrix for queue lengths (60 rows)
queue_lengths = zeros(num_intervals, 1);
% Get queue counter
queue_counters_1 = Link_Num_1.QueueCounters.GetAll;
qc1 = queue_counters_1{1}; % First queue counter
% Display queue counter info
disp([‘Number of queue counters: ‘, num2str(length(queue_counters_1))]);
disp([‘Queue Counter Object: ‘, class(qc1)]);
disp([‘Queue Counter Name: ‘, qc1.get(‘AttValue’, ‘Name’)]);
% Run simulation and collect queue length every 120 seconds
interval_idx = 0; % Counter for interval index
for t = 1:interval:simulation_duration
% Run simulation for 120 seconds
for step = 1:interval
sim.RunSingleStep;
end
% Increment interval index
interval_idx = interval_idx + 1;
% Get queue length
queue_length = qc1.get(‘AttValue’, ‘QLen(Current, Last)’);
if isnan(queue_length)
queue_length = 0; % Replace NaN with 0
end
queue_lengths(interval_idx, 1) = queue_length;
% Display queue length for this interval
disp([‘Time ‘, num2str(t), ‘s: Queue Length = ‘, num2str(queue_length)]);
end
disp(‘Queue Length collection complete.’); help MATLAB Answers — New Questions