Category: Matlab
Category Archives: Matlab
extracting table data from a plot picture question
Hello,I have many plots like this in the data sheet.
there is a java tools which manually allow to extract the data of each plot.
Is the a way in matlab to do it?
Thanks.Hello,I have many plots like this in the data sheet.
there is a java tools which manually allow to extract the data of each plot.
Is the a way in matlab to do it?
Thanks. Hello,I have many plots like this in the data sheet.
there is a java tools which manually allow to extract the data of each plot.
Is the a way in matlab to do it?
Thanks. plot, photo MATLAB Answers — New Questions
Matlab plots step response vs timestep number instead of time in seconds
s = tf(‘s’); %Laplace variable
t = 0:0.01:10; %time vector start, dt , end
K = 1;
KI = 0;
sysT = (K * s + KI) / ( ( s^3 + 3*s^2 + (2+K)*s + KI) );
[y,t] = step(sysT,t);
plot(y);
Above snippet shows issue. The issue is that plot(y); plots the step response vs the number of timesteps instead of vs time in secs. For instance if dt = 0.01, the abcissa is in the 100’s. If dt = 0.001, the abcissa is in the 1000’s. If dt = 0.0001, the abcissa is in the 10000’s. How can I just plot vs time in seconds??s = tf(‘s’); %Laplace variable
t = 0:0.01:10; %time vector start, dt , end
K = 1;
KI = 0;
sysT = (K * s + KI) / ( ( s^3 + 3*s^2 + (2+K)*s + KI) );
[y,t] = step(sysT,t);
plot(y);
Above snippet shows issue. The issue is that plot(y); plots the step response vs the number of timesteps instead of vs time in secs. For instance if dt = 0.01, the abcissa is in the 100’s. If dt = 0.001, the abcissa is in the 1000’s. If dt = 0.0001, the abcissa is in the 10000’s. How can I just plot vs time in seconds?? s = tf(‘s’); %Laplace variable
t = 0:0.01:10; %time vector start, dt , end
K = 1;
KI = 0;
sysT = (K * s + KI) / ( ( s^3 + 3*s^2 + (2+K)*s + KI) );
[y,t] = step(sysT,t);
plot(y);
Above snippet shows issue. The issue is that plot(y); plots the step response vs the number of timesteps instead of vs time in secs. For instance if dt = 0.01, the abcissa is in the 100’s. If dt = 0.001, the abcissa is in the 1000’s. If dt = 0.0001, the abcissa is in the 10000’s. How can I just plot vs time in seconds?? plot vs timestep number MATLAB Answers — New Questions
embedding inset plots in subplots matlab
Hi, I am trying to plots an insets plots in aubplots but only the last subplot and inset plots are shown. Please can someone help with this?
% Define xi_select and slope_select for main and inset plots
xi_select = [1, 10, 11, 12];
slope_select = [1, 3, 4, 5, 7, 9];
% Create a tiled layout with 2 rows and 3 columns of subplots
t = tiledlayout(2, 3, ‘TileSpacing’, ‘compact’, ‘Padding’, ‘compact’);
% Define custom colors (green to red gradient)
num_colors = length(xi_select);
custom_colors = [linspace(0, 1, num_colors)’, linspace(1, 0, num_colors)’, zeros(num_colors, 1)];
custom_linestyles = repmat({‘–‘}, 1, num_colors); % All dashed lines
% Initialize arrays for legend
legend_labels = {}; % Cell array to store legend labels
legend_index = 0; % Initialize legend index
plot_handles = []; % Array for storing plot handles
for j = 1:length(slope_select) % Loop through selected ramp_slope
% Create the main subplot
ax = nexttile; % Move to the next tile for each subplot
hold(ax, ‘on’); % Hold on to plot multiple lines in the same subplot
% Loop through selected xi values for the main plots
for i = 1:length(xi_select)
% Find the switching times for the current xi and ramp_slope
transitions = find(switching(:, xi_select(i), slope_select(j)));
if ~isempty(transitions)
% Plot the uxlt data at the switching times for this xi and ramp_slope
for t_idx = transitions
% Extract the uxlt data for the current time point
uxlt_data = squeeze(uxlt(ym, :, xi_select(i), slope_select(j))); % Dimension: y, xi, ramp_slope
% Proper LaTeX syntax for the legend entry, omitting time
display_name = sprintf(‘$\xi=%.2f$’, xi(xi_select(i)));
% Plot the data with specified color and linestyle
h = plot(ax, tarray, uxlt_data, ‘LineWidth’, 1.5, …
‘Color’, custom_colors(i, :), ‘LineStyle’, custom_linestyles{i});
% Only add the label and handle once to the legend
if ~ismember(display_name, legend_labels)
legend_index = legend_index + 1;
plot_handles(legend_index) = h(1); % Store only the first handle
legend_labels{legend_index} = display_name; % Append label
end
end
end
end
% Add labels and title to each subplot
xlabel(ax, ‘Time (s)’, ‘Interpreter’, ‘latex’);
ylabel(ax, ‘$int u_L , mathrm{dz}$’, ‘Interpreter’, ‘latex’);
xlim(ax, [min(tarray), max(tarray)]);
ylim(ax, [0, 2.5e-04]);
% Add subplot numbering and S_{rf} value
title(ax, sprintf(‘(%c) $S_{rf} = %.2f$’, ‘a’ + j – 1, ramp_slope(slope_select(j))), ‘Interpreter’, ‘latex’);
box(ax, ‘on’); % Place a box around the current subplot
% Add inset plots
inset_pos = ax.Position; % Get the position of the current subplot
if j == 1
% The first inset plot on the top left of the first subplot
inset_pos = [inset_pos(1) + 0.1 * inset_pos(3), inset_pos(2) + 0.65 * inset_pos(4), 0.15, 0.15];
else
% Remaining inset plots on the top right of the respective subplots
inset_pos = [inset_pos(1) + 0.6 * inset_pos(3), inset_pos(2) + 0.65 * inset_pos(4), 0.15, 0.15];
end
% Create new axes for inset plots, without attaching them to the main subplot axes
inset_ax = axes(‘Position’, inset_pos); % Create inset axes with adjusted position
hold(inset_ax, ‘on’); % Hold on inset axes to plot multiple lines
% Loop through selected xi values for the inset plots
for i = 1:length(xi_select)
% Find the switching times for the current xi and ramp_slope
transitions = find(switching(:, xi_select(i), slope_select(j)));
if ~isempty(transitions)
% Plot the uxl data in the inset plot
for t_idx = transitions
% Extract the uxl data for the current time point
uxl_data = squeeze(uxl(:, xi_select(i), slope_select(j))); % Dimension: y, xi, ramp_slope
% Plot the data in the inset with color and linestyle
plot(inset_ax, y, uxl_data, ‘LineWidth’, 1.5, …
‘Color’, custom_colors(i, :), ‘LineStyle’, custom_linestyles{i});
end
end
end
% Add labels to inset
xlabel(inset_ax, ‘$z$’, ‘Interpreter’, ‘latex’);
ylabel(inset_ax, ‘$int u_L , mathrm{dz}$’, ‘Interpreter’, ‘latex’);
xlim(inset_ax, [min(y), max(y)]);
hold(inset_ax, ‘off’); % Release hold on the inset axes
end
% Create a global legend (optional, if needed)
lgd = legend(plot_handles, legend_labels, ‘Interpreter’, ‘latex’, ‘NumColumns’, 2);
% Ensure that the entire figure has a box around it
box on;Hi, I am trying to plots an insets plots in aubplots but only the last subplot and inset plots are shown. Please can someone help with this?
% Define xi_select and slope_select for main and inset plots
xi_select = [1, 10, 11, 12];
slope_select = [1, 3, 4, 5, 7, 9];
% Create a tiled layout with 2 rows and 3 columns of subplots
t = tiledlayout(2, 3, ‘TileSpacing’, ‘compact’, ‘Padding’, ‘compact’);
% Define custom colors (green to red gradient)
num_colors = length(xi_select);
custom_colors = [linspace(0, 1, num_colors)’, linspace(1, 0, num_colors)’, zeros(num_colors, 1)];
custom_linestyles = repmat({‘–‘}, 1, num_colors); % All dashed lines
% Initialize arrays for legend
legend_labels = {}; % Cell array to store legend labels
legend_index = 0; % Initialize legend index
plot_handles = []; % Array for storing plot handles
for j = 1:length(slope_select) % Loop through selected ramp_slope
% Create the main subplot
ax = nexttile; % Move to the next tile for each subplot
hold(ax, ‘on’); % Hold on to plot multiple lines in the same subplot
% Loop through selected xi values for the main plots
for i = 1:length(xi_select)
% Find the switching times for the current xi and ramp_slope
transitions = find(switching(:, xi_select(i), slope_select(j)));
if ~isempty(transitions)
% Plot the uxlt data at the switching times for this xi and ramp_slope
for t_idx = transitions
% Extract the uxlt data for the current time point
uxlt_data = squeeze(uxlt(ym, :, xi_select(i), slope_select(j))); % Dimension: y, xi, ramp_slope
% Proper LaTeX syntax for the legend entry, omitting time
display_name = sprintf(‘$\xi=%.2f$’, xi(xi_select(i)));
% Plot the data with specified color and linestyle
h = plot(ax, tarray, uxlt_data, ‘LineWidth’, 1.5, …
‘Color’, custom_colors(i, :), ‘LineStyle’, custom_linestyles{i});
% Only add the label and handle once to the legend
if ~ismember(display_name, legend_labels)
legend_index = legend_index + 1;
plot_handles(legend_index) = h(1); % Store only the first handle
legend_labels{legend_index} = display_name; % Append label
end
end
end
end
% Add labels and title to each subplot
xlabel(ax, ‘Time (s)’, ‘Interpreter’, ‘latex’);
ylabel(ax, ‘$int u_L , mathrm{dz}$’, ‘Interpreter’, ‘latex’);
xlim(ax, [min(tarray), max(tarray)]);
ylim(ax, [0, 2.5e-04]);
% Add subplot numbering and S_{rf} value
title(ax, sprintf(‘(%c) $S_{rf} = %.2f$’, ‘a’ + j – 1, ramp_slope(slope_select(j))), ‘Interpreter’, ‘latex’);
box(ax, ‘on’); % Place a box around the current subplot
% Add inset plots
inset_pos = ax.Position; % Get the position of the current subplot
if j == 1
% The first inset plot on the top left of the first subplot
inset_pos = [inset_pos(1) + 0.1 * inset_pos(3), inset_pos(2) + 0.65 * inset_pos(4), 0.15, 0.15];
else
% Remaining inset plots on the top right of the respective subplots
inset_pos = [inset_pos(1) + 0.6 * inset_pos(3), inset_pos(2) + 0.65 * inset_pos(4), 0.15, 0.15];
end
% Create new axes for inset plots, without attaching them to the main subplot axes
inset_ax = axes(‘Position’, inset_pos); % Create inset axes with adjusted position
hold(inset_ax, ‘on’); % Hold on inset axes to plot multiple lines
% Loop through selected xi values for the inset plots
for i = 1:length(xi_select)
% Find the switching times for the current xi and ramp_slope
transitions = find(switching(:, xi_select(i), slope_select(j)));
if ~isempty(transitions)
% Plot the uxl data in the inset plot
for t_idx = transitions
% Extract the uxl data for the current time point
uxl_data = squeeze(uxl(:, xi_select(i), slope_select(j))); % Dimension: y, xi, ramp_slope
% Plot the data in the inset with color and linestyle
plot(inset_ax, y, uxl_data, ‘LineWidth’, 1.5, …
‘Color’, custom_colors(i, :), ‘LineStyle’, custom_linestyles{i});
end
end
end
% Add labels to inset
xlabel(inset_ax, ‘$z$’, ‘Interpreter’, ‘latex’);
ylabel(inset_ax, ‘$int u_L , mathrm{dz}$’, ‘Interpreter’, ‘latex’);
xlim(inset_ax, [min(y), max(y)]);
hold(inset_ax, ‘off’); % Release hold on the inset axes
end
% Create a global legend (optional, if needed)
lgd = legend(plot_handles, legend_labels, ‘Interpreter’, ‘latex’, ‘NumColumns’, 2);
% Ensure that the entire figure has a box around it
box on; Hi, I am trying to plots an insets plots in aubplots but only the last subplot and inset plots are shown. Please can someone help with this?
% Define xi_select and slope_select for main and inset plots
xi_select = [1, 10, 11, 12];
slope_select = [1, 3, 4, 5, 7, 9];
% Create a tiled layout with 2 rows and 3 columns of subplots
t = tiledlayout(2, 3, ‘TileSpacing’, ‘compact’, ‘Padding’, ‘compact’);
% Define custom colors (green to red gradient)
num_colors = length(xi_select);
custom_colors = [linspace(0, 1, num_colors)’, linspace(1, 0, num_colors)’, zeros(num_colors, 1)];
custom_linestyles = repmat({‘–‘}, 1, num_colors); % All dashed lines
% Initialize arrays for legend
legend_labels = {}; % Cell array to store legend labels
legend_index = 0; % Initialize legend index
plot_handles = []; % Array for storing plot handles
for j = 1:length(slope_select) % Loop through selected ramp_slope
% Create the main subplot
ax = nexttile; % Move to the next tile for each subplot
hold(ax, ‘on’); % Hold on to plot multiple lines in the same subplot
% Loop through selected xi values for the main plots
for i = 1:length(xi_select)
% Find the switching times for the current xi and ramp_slope
transitions = find(switching(:, xi_select(i), slope_select(j)));
if ~isempty(transitions)
% Plot the uxlt data at the switching times for this xi and ramp_slope
for t_idx = transitions
% Extract the uxlt data for the current time point
uxlt_data = squeeze(uxlt(ym, :, xi_select(i), slope_select(j))); % Dimension: y, xi, ramp_slope
% Proper LaTeX syntax for the legend entry, omitting time
display_name = sprintf(‘$\xi=%.2f$’, xi(xi_select(i)));
% Plot the data with specified color and linestyle
h = plot(ax, tarray, uxlt_data, ‘LineWidth’, 1.5, …
‘Color’, custom_colors(i, :), ‘LineStyle’, custom_linestyles{i});
% Only add the label and handle once to the legend
if ~ismember(display_name, legend_labels)
legend_index = legend_index + 1;
plot_handles(legend_index) = h(1); % Store only the first handle
legend_labels{legend_index} = display_name; % Append label
end
end
end
end
% Add labels and title to each subplot
xlabel(ax, ‘Time (s)’, ‘Interpreter’, ‘latex’);
ylabel(ax, ‘$int u_L , mathrm{dz}$’, ‘Interpreter’, ‘latex’);
xlim(ax, [min(tarray), max(tarray)]);
ylim(ax, [0, 2.5e-04]);
% Add subplot numbering and S_{rf} value
title(ax, sprintf(‘(%c) $S_{rf} = %.2f$’, ‘a’ + j – 1, ramp_slope(slope_select(j))), ‘Interpreter’, ‘latex’);
box(ax, ‘on’); % Place a box around the current subplot
% Add inset plots
inset_pos = ax.Position; % Get the position of the current subplot
if j == 1
% The first inset plot on the top left of the first subplot
inset_pos = [inset_pos(1) + 0.1 * inset_pos(3), inset_pos(2) + 0.65 * inset_pos(4), 0.15, 0.15];
else
% Remaining inset plots on the top right of the respective subplots
inset_pos = [inset_pos(1) + 0.6 * inset_pos(3), inset_pos(2) + 0.65 * inset_pos(4), 0.15, 0.15];
end
% Create new axes for inset plots, without attaching them to the main subplot axes
inset_ax = axes(‘Position’, inset_pos); % Create inset axes with adjusted position
hold(inset_ax, ‘on’); % Hold on inset axes to plot multiple lines
% Loop through selected xi values for the inset plots
for i = 1:length(xi_select)
% Find the switching times for the current xi and ramp_slope
transitions = find(switching(:, xi_select(i), slope_select(j)));
if ~isempty(transitions)
% Plot the uxl data in the inset plot
for t_idx = transitions
% Extract the uxl data for the current time point
uxl_data = squeeze(uxl(:, xi_select(i), slope_select(j))); % Dimension: y, xi, ramp_slope
% Plot the data in the inset with color and linestyle
plot(inset_ax, y, uxl_data, ‘LineWidth’, 1.5, …
‘Color’, custom_colors(i, :), ‘LineStyle’, custom_linestyles{i});
end
end
end
% Add labels to inset
xlabel(inset_ax, ‘$z$’, ‘Interpreter’, ‘latex’);
ylabel(inset_ax, ‘$int u_L , mathrm{dz}$’, ‘Interpreter’, ‘latex’);
xlim(inset_ax, [min(y), max(y)]);
hold(inset_ax, ‘off’); % Release hold on the inset axes
end
% Create a global legend (optional, if needed)
lgd = legend(plot_handles, legend_labels, ‘Interpreter’, ‘latex’, ‘NumColumns’, 2);
% Ensure that the entire figure has a box around it
box on; insets, subplots, figures MATLAB Answers — New Questions
How to write code for repetitive process?
Hello.
Given:
Variable components: species_1 and species_2;
Initial values: species_1=1000 g and species_2=200 g;
Process parameters: timecut=2 hour, timecon=1hour, kf=0.1 1/hour
The components are related to each other by a reaction according to the law of mass action:
species_1 -> species_2: kf*species_1
In the time interval 0<=time<=timecut, the mass of the component species_1 decreases while the mass of the component species_2 increases. At the point time=timecut, the masses of the components return to their initial values. Two sawtooth patterns are formed on the charts: one sawtooth on chart for species_1 and another inverted sawtooth on chart for species_2.
Then, during the timecon, the masses of components retain their original values: "shelves" are formed. Codes in the Simbiology Builder:
Trigger: time>=timecut
Event FCNS:
kf=0
species_1=1000
species_2=200
If time>=timecut+timecon and kf=0.1, the mass of the species_1 component decreases and the mass of the species_2 component increases. No saw teeth and shelves are formed.
How should the code be written in Simbiology so that the "tooth-shelf" process are repeated n times?Hello.
Given:
Variable components: species_1 and species_2;
Initial values: species_1=1000 g and species_2=200 g;
Process parameters: timecut=2 hour, timecon=1hour, kf=0.1 1/hour
The components are related to each other by a reaction according to the law of mass action:
species_1 -> species_2: kf*species_1
In the time interval 0<=time<=timecut, the mass of the component species_1 decreases while the mass of the component species_2 increases. At the point time=timecut, the masses of the components return to their initial values. Two sawtooth patterns are formed on the charts: one sawtooth on chart for species_1 and another inverted sawtooth on chart for species_2.
Then, during the timecon, the masses of components retain their original values: "shelves" are formed. Codes in the Simbiology Builder:
Trigger: time>=timecut
Event FCNS:
kf=0
species_1=1000
species_2=200
If time>=timecut+timecon and kf=0.1, the mass of the species_1 component decreases and the mass of the species_2 component increases. No saw teeth and shelves are formed.
How should the code be written in Simbiology so that the "tooth-shelf" process are repeated n times? Hello.
Given:
Variable components: species_1 and species_2;
Initial values: species_1=1000 g and species_2=200 g;
Process parameters: timecut=2 hour, timecon=1hour, kf=0.1 1/hour
The components are related to each other by a reaction according to the law of mass action:
species_1 -> species_2: kf*species_1
In the time interval 0<=time<=timecut, the mass of the component species_1 decreases while the mass of the component species_2 increases. At the point time=timecut, the masses of the components return to their initial values. Two sawtooth patterns are formed on the charts: one sawtooth on chart for species_1 and another inverted sawtooth on chart for species_2.
Then, during the timecon, the masses of components retain their original values: "shelves" are formed. Codes in the Simbiology Builder:
Trigger: time>=timecut
Event FCNS:
kf=0
species_1=1000
species_2=200
If time>=timecut+timecon and kf=0.1, the mass of the species_1 component decreases and the mass of the species_2 component increases. No saw teeth and shelves are formed.
How should the code be written in Simbiology so that the "tooth-shelf" process are repeated n times? programming, cycle MATLAB Answers — New Questions
Check tcpclient connection status
Hi, I’m currently using tcpclient command to establish tcpip communication with an external device (not tcpip() from instrument toolbox).
Sometimes, the connection is not stable and when I write data it returns error: ‘An existing connection was forcibly closed by the remote host’.
Therefore, I want to implement a method to check the connection before I write / read from the connection. However, I just couldn’t find much information regarding tcpclient.
I have attempted the following:
% connect
t=tcpclient(‘172.1.1.102′,50000,’Timeout’,1,’ConnectTimeout’,3);
Here, before running the I deliberately disconnected Ethernet cable just want to test trigger the error:
% My intention: try a write / read to check if an error returns
try
write(t,0);
read(t);
disp(‘send succesfull’);
catch ME
disp(‘connection lost’);
disp(ME.identifier);
end
For the first run ‘An existing connection was forcibly closed by the remote host’ still appears in the command window and the ‘send successful’ message is printed, catch statement is skipped. However, a second run will jump into catch statement though.
If I run the try-catch step by step, when it reaches ‘write(t,0)’ statement it returns the ”An existing … remote host”, and continue to ‘read(t)’ statement, and jumps into catch statement.
I couldn’t quite understand why this happened.
Thanks for your help very much!Hi, I’m currently using tcpclient command to establish tcpip communication with an external device (not tcpip() from instrument toolbox).
Sometimes, the connection is not stable and when I write data it returns error: ‘An existing connection was forcibly closed by the remote host’.
Therefore, I want to implement a method to check the connection before I write / read from the connection. However, I just couldn’t find much information regarding tcpclient.
I have attempted the following:
% connect
t=tcpclient(‘172.1.1.102′,50000,’Timeout’,1,’ConnectTimeout’,3);
Here, before running the I deliberately disconnected Ethernet cable just want to test trigger the error:
% My intention: try a write / read to check if an error returns
try
write(t,0);
read(t);
disp(‘send succesfull’);
catch ME
disp(‘connection lost’);
disp(ME.identifier);
end
For the first run ‘An existing connection was forcibly closed by the remote host’ still appears in the command window and the ‘send successful’ message is printed, catch statement is skipped. However, a second run will jump into catch statement though.
If I run the try-catch step by step, when it reaches ‘write(t,0)’ statement it returns the ”An existing … remote host”, and continue to ‘read(t)’ statement, and jumps into catch statement.
I couldn’t quite understand why this happened.
Thanks for your help very much! Hi, I’m currently using tcpclient command to establish tcpip communication with an external device (not tcpip() from instrument toolbox).
Sometimes, the connection is not stable and when I write data it returns error: ‘An existing connection was forcibly closed by the remote host’.
Therefore, I want to implement a method to check the connection before I write / read from the connection. However, I just couldn’t find much information regarding tcpclient.
I have attempted the following:
% connect
t=tcpclient(‘172.1.1.102′,50000,’Timeout’,1,’ConnectTimeout’,3);
Here, before running the I deliberately disconnected Ethernet cable just want to test trigger the error:
% My intention: try a write / read to check if an error returns
try
write(t,0);
read(t);
disp(‘send succesfull’);
catch ME
disp(‘connection lost’);
disp(ME.identifier);
end
For the first run ‘An existing connection was forcibly closed by the remote host’ still appears in the command window and the ‘send successful’ message is printed, catch statement is skipped. However, a second run will jump into catch statement though.
If I run the try-catch step by step, when it reaches ‘write(t,0)’ statement it returns the ”An existing … remote host”, and continue to ‘read(t)’ statement, and jumps into catch statement.
I couldn’t quite understand why this happened.
Thanks for your help very much! matlab, tcpip, tcpclient, connection MATLAB Answers — New Questions
How to export 500 images in one file
I have around 500 images which I want to export into one .xls .word or .pdf in 3 collums. I tried putting them all in one figure but then they become extremely small. If I create many separete figures by 3, I don´t know how to export them all into one file. I tried putting all of the images into table but then the table doesn´t generate because I run out of memorry. If I were to guess, it most likely tries to put every single value of the picture into a separated cell.
How do I make pictures in the table to be saved in their pictural form?
clear all; clc; close all;
dir_img_AP=dir(‘**/NUSCH*AP/**/*.jpg’);
dir_img_JS=dir(‘**/NUSCH*JS/**/*.jpg’);
dir_img_LZ=dir(‘**/NUSCH*LZ/**/*.jpg’);
n_img_AP=numel(dir_img_AP);
n_img_JS=numel(dir_img_JS);
n_img_LZ=numel(dir_img_LZ);
n_img=max([n_img_AP,n_img_JS,n_img_LZ]);
T=cell(n_img,1);
for i=1:n_img_AP
file_path_AP=[dir_img_AP(i).folder, ‘/’,dir_img_AP(i).name];
filename_AP = dir_img_AP(i).name;
pic_AP = imread(filename_AP);
T{i,1} = pic_AP;
end
for i=1:n_img_JS
file_path_JS=[dir_img_JS(i).folder, ‘/’,dir_img_JS(i).name];
filename_JS = dir_img_JS(i).name;
pic_JS = imread(filename_JS);
T{i,2} = pic_JS;
end
for i=1:n_img_LZ
file_path_LZ=[dir_img_LZ(i).folder, ‘/’,dir_img_LZ(i).name];
filename_LZ = dir_img_LZ(i).name;
pic_LZ = imread(filename_LZ);
T{i,3} = pic_LZ;
end
table=cell2table(T);
arr = table2array(table);
% imshow(arr);
f_name=’pic.xls’;
% writetable(table,f_name)I have around 500 images which I want to export into one .xls .word or .pdf in 3 collums. I tried putting them all in one figure but then they become extremely small. If I create many separete figures by 3, I don´t know how to export them all into one file. I tried putting all of the images into table but then the table doesn´t generate because I run out of memorry. If I were to guess, it most likely tries to put every single value of the picture into a separated cell.
How do I make pictures in the table to be saved in their pictural form?
clear all; clc; close all;
dir_img_AP=dir(‘**/NUSCH*AP/**/*.jpg’);
dir_img_JS=dir(‘**/NUSCH*JS/**/*.jpg’);
dir_img_LZ=dir(‘**/NUSCH*LZ/**/*.jpg’);
n_img_AP=numel(dir_img_AP);
n_img_JS=numel(dir_img_JS);
n_img_LZ=numel(dir_img_LZ);
n_img=max([n_img_AP,n_img_JS,n_img_LZ]);
T=cell(n_img,1);
for i=1:n_img_AP
file_path_AP=[dir_img_AP(i).folder, ‘/’,dir_img_AP(i).name];
filename_AP = dir_img_AP(i).name;
pic_AP = imread(filename_AP);
T{i,1} = pic_AP;
end
for i=1:n_img_JS
file_path_JS=[dir_img_JS(i).folder, ‘/’,dir_img_JS(i).name];
filename_JS = dir_img_JS(i).name;
pic_JS = imread(filename_JS);
T{i,2} = pic_JS;
end
for i=1:n_img_LZ
file_path_LZ=[dir_img_LZ(i).folder, ‘/’,dir_img_LZ(i).name];
filename_LZ = dir_img_LZ(i).name;
pic_LZ = imread(filename_LZ);
T{i,3} = pic_LZ;
end
table=cell2table(T);
arr = table2array(table);
% imshow(arr);
f_name=’pic.xls’;
% writetable(table,f_name) I have around 500 images which I want to export into one .xls .word or .pdf in 3 collums. I tried putting them all in one figure but then they become extremely small. If I create many separete figures by 3, I don´t know how to export them all into one file. I tried putting all of the images into table but then the table doesn´t generate because I run out of memorry. If I were to guess, it most likely tries to put every single value of the picture into a separated cell.
How do I make pictures in the table to be saved in their pictural form?
clear all; clc; close all;
dir_img_AP=dir(‘**/NUSCH*AP/**/*.jpg’);
dir_img_JS=dir(‘**/NUSCH*JS/**/*.jpg’);
dir_img_LZ=dir(‘**/NUSCH*LZ/**/*.jpg’);
n_img_AP=numel(dir_img_AP);
n_img_JS=numel(dir_img_JS);
n_img_LZ=numel(dir_img_LZ);
n_img=max([n_img_AP,n_img_JS,n_img_LZ]);
T=cell(n_img,1);
for i=1:n_img_AP
file_path_AP=[dir_img_AP(i).folder, ‘/’,dir_img_AP(i).name];
filename_AP = dir_img_AP(i).name;
pic_AP = imread(filename_AP);
T{i,1} = pic_AP;
end
for i=1:n_img_JS
file_path_JS=[dir_img_JS(i).folder, ‘/’,dir_img_JS(i).name];
filename_JS = dir_img_JS(i).name;
pic_JS = imread(filename_JS);
T{i,2} = pic_JS;
end
for i=1:n_img_LZ
file_path_LZ=[dir_img_LZ(i).folder, ‘/’,dir_img_LZ(i).name];
filename_LZ = dir_img_LZ(i).name;
pic_LZ = imread(filename_LZ);
T{i,3} = pic_LZ;
end
table=cell2table(T);
arr = table2array(table);
% imshow(arr);
f_name=’pic.xls’;
% writetable(table,f_name) database, export, image MATLAB Answers — New Questions
store images in a table
Hello,
I have three images and want to store them in a table. I wrote this in command line:
dinfo = dir(‘*.jpg’);
T = table();
for K = 1 : length(dinfo)
filename = dinfo(K).name;
filecontent = imread(filename);
T{filename,1} = filecontent;
end
It gives the error:
To assign to or create a variable in a table, the number of rows must match the height of the table.
Secondly, I want to make my three images equal in size, as we have to make the size of variables in rows equal for tables.
Help needed. Thanks in advance.Hello,
I have three images and want to store them in a table. I wrote this in command line:
dinfo = dir(‘*.jpg’);
T = table();
for K = 1 : length(dinfo)
filename = dinfo(K).name;
filecontent = imread(filename);
T{filename,1} = filecontent;
end
It gives the error:
To assign to or create a variable in a table, the number of rows must match the height of the table.
Secondly, I want to make my three images equal in size, as we have to make the size of variables in rows equal for tables.
Help needed. Thanks in advance. Hello,
I have three images and want to store them in a table. I wrote this in command line:
dinfo = dir(‘*.jpg’);
T = table();
for K = 1 : length(dinfo)
filename = dinfo(K).name;
filecontent = imread(filename);
T{filename,1} = filecontent;
end
It gives the error:
To assign to or create a variable in a table, the number of rows must match the height of the table.
Secondly, I want to make my three images equal in size, as we have to make the size of variables in rows equal for tables.
Help needed. Thanks in advance. matlab tables, table, database MATLAB Answers — New Questions
Cannot run kernel – Simulink Desktop Real-time
When I try to use the Desktop-Real-Time/Stream input in the simulink, and start a simulation, it apears a error message like "cannot acess kernel". Why do this happen? How it can be solved? Thanks!
The error message is: "Hardware time cannot be allocated. Real time kernel cannot run"When I try to use the Desktop-Real-Time/Stream input in the simulink, and start a simulation, it apears a error message like "cannot acess kernel". Why do this happen? How it can be solved? Thanks!
The error message is: "Hardware time cannot be allocated. Real time kernel cannot run" When I try to use the Desktop-Real-Time/Stream input in the simulink, and start a simulation, it apears a error message like "cannot acess kernel". Why do this happen? How it can be solved? Thanks!
The error message is: "Hardware time cannot be allocated. Real time kernel cannot run" simulink, kernel MATLAB Answers — New Questions
problem in simulink (FOPID controller)
Derivative of state ‘1’ in block ‘FOPIDC/Fractional PID controller1/Fractional derivative1/Transfer
Fcn1′ at time 3.2188803386168852 is not finite. The simulation will be stopped. There may be a
singularity in the solution. If not, try reducing the step size (either by reducing the fixed step
size or by tightening the error tolerances)
how can I solve this errorDerivative of state ‘1’ in block ‘FOPIDC/Fractional PID controller1/Fractional derivative1/Transfer
Fcn1′ at time 3.2188803386168852 is not finite. The simulation will be stopped. There may be a
singularity in the solution. If not, try reducing the step size (either by reducing the fixed step
size or by tightening the error tolerances)
how can I solve this error Derivative of state ‘1’ in block ‘FOPIDC/Fractional PID controller1/Fractional derivative1/Transfer
Fcn1′ at time 3.2188803386168852 is not finite. The simulation will be stopped. There may be a
singularity in the solution. If not, try reducing the step size (either by reducing the fixed step
size or by tightening the error tolerances)
how can I solve this error fopid MATLAB Answers — New Questions
How to properly make a circular histogram?
I have data points which are the angle and distance around a central point. I would like to make a histogram of these points so I can visualise their distribution and also perform some analyses on their density etc.
For now, I make a 2D histogram, treating the data points as if they are cartesian X,Y coordinates. I then transform the bin centers into polar coordinates and replot the data, like this:
% create data points
theta = normrnd(0,0.5,1000,1);
rad = 100.*rand(1000,1);
figure
subplot(1,3,1)
polarscatter(theta,rad,10,’k’,’filled’,’o’)
title(‘data points’)
% prepare bins
theta_bins = linspace(-pi,pi,120);
rad_bins = 0:5:100;
% ‘normal’ histogram
f = histcounts2(rad,theta,rad_bins,theta_bins);
subplot(1,3,2)
imagesc(f)
daspect([1 1 1])
title(‘histogram in cartesian coordinates’)
% transform bin coordinates
[theta,rad] = meshgrid(linspace(min(theta_bins),max(theta_bins),length(theta_bins)-1),linspace(min(rad_bins),max(rad_bins),length(rad_bins)-1));
[X,Y] = pol2cart(theta,rad);
subplot(1,3,3)
s = surf(X,Y,f);
s.EdgeColor = ‘none’;
view(0,90);
daspect([1 1 1])
axis xy
title(‘histogram in polar coordinates’)
However, the resulting histogram is not really ideal – the bins are not homogeneous because they get larger as the radius increases. This is due to the fact that I made the histogram in a cartesian reference frame.
I was wondering if there is a better way to go about this? Some sort of circular histogram with circular bands of triangular bins? Or hexagonal bins? Can anyone suggest anything?
Thanks for any help.I have data points which are the angle and distance around a central point. I would like to make a histogram of these points so I can visualise their distribution and also perform some analyses on their density etc.
For now, I make a 2D histogram, treating the data points as if they are cartesian X,Y coordinates. I then transform the bin centers into polar coordinates and replot the data, like this:
% create data points
theta = normrnd(0,0.5,1000,1);
rad = 100.*rand(1000,1);
figure
subplot(1,3,1)
polarscatter(theta,rad,10,’k’,’filled’,’o’)
title(‘data points’)
% prepare bins
theta_bins = linspace(-pi,pi,120);
rad_bins = 0:5:100;
% ‘normal’ histogram
f = histcounts2(rad,theta,rad_bins,theta_bins);
subplot(1,3,2)
imagesc(f)
daspect([1 1 1])
title(‘histogram in cartesian coordinates’)
% transform bin coordinates
[theta,rad] = meshgrid(linspace(min(theta_bins),max(theta_bins),length(theta_bins)-1),linspace(min(rad_bins),max(rad_bins),length(rad_bins)-1));
[X,Y] = pol2cart(theta,rad);
subplot(1,3,3)
s = surf(X,Y,f);
s.EdgeColor = ‘none’;
view(0,90);
daspect([1 1 1])
axis xy
title(‘histogram in polar coordinates’)
However, the resulting histogram is not really ideal – the bins are not homogeneous because they get larger as the radius increases. This is due to the fact that I made the histogram in a cartesian reference frame.
I was wondering if there is a better way to go about this? Some sort of circular histogram with circular bands of triangular bins? Or hexagonal bins? Can anyone suggest anything?
Thanks for any help. I have data points which are the angle and distance around a central point. I would like to make a histogram of these points so I can visualise their distribution and also perform some analyses on their density etc.
For now, I make a 2D histogram, treating the data points as if they are cartesian X,Y coordinates. I then transform the bin centers into polar coordinates and replot the data, like this:
% create data points
theta = normrnd(0,0.5,1000,1);
rad = 100.*rand(1000,1);
figure
subplot(1,3,1)
polarscatter(theta,rad,10,’k’,’filled’,’o’)
title(‘data points’)
% prepare bins
theta_bins = linspace(-pi,pi,120);
rad_bins = 0:5:100;
% ‘normal’ histogram
f = histcounts2(rad,theta,rad_bins,theta_bins);
subplot(1,3,2)
imagesc(f)
daspect([1 1 1])
title(‘histogram in cartesian coordinates’)
% transform bin coordinates
[theta,rad] = meshgrid(linspace(min(theta_bins),max(theta_bins),length(theta_bins)-1),linspace(min(rad_bins),max(rad_bins),length(rad_bins)-1));
[X,Y] = pol2cart(theta,rad);
subplot(1,3,3)
s = surf(X,Y,f);
s.EdgeColor = ‘none’;
view(0,90);
daspect([1 1 1])
axis xy
title(‘histogram in polar coordinates’)
However, the resulting histogram is not really ideal – the bins are not homogeneous because they get larger as the radius increases. This is due to the fact that I made the histogram in a cartesian reference frame.
I was wondering if there is a better way to go about this? Some sort of circular histogram with circular bands of triangular bins? Or hexagonal bins? Can anyone suggest anything?
Thanks for any help. circular, histogram, polar, visualisation MATLAB Answers — New Questions
How to define input parameters for BytesAvailableFcn (tcpclient)
Hy all,
my problem concerns the use of input arguments when I define the BytesAvailableFcn of a tcpclient connection.
I create a tcpclient connection:
t = tcpclient(‘address’, port);
And I send a request to the server (which starts automatically to send data):
write( t, ‘request’ );
I want to have a callback function triggered by a bytes available event:
configureCallback( t, "terminator", @MyCallbackFcn );
MyCallbackFcn is written in a separated MyCallbackFcn.m file. The callback function MyCallbackFcn is triggeredd whenever a terminator is available to be read from the remote host specified by the TCP/IP client.
At the moment, MyCallbackFcn uses global parameters (var1, var2, etc.) defined in the main program:
function MyCallbackFcn( src, ~ )
global var1 var2
…
end
This algorithm works well. But in order to avoid the use of global parameters, I would like to define input parameters for MyCallbackFcn fonction. My problems start here, because I do not find the right form to write:
the definition of the callback function in the main program : configureCallback( t,…
the function MyCallbackFcn in the MyCallbackFcn.m file
Thank you in advance for your help.
RaphaëlHy all,
my problem concerns the use of input arguments when I define the BytesAvailableFcn of a tcpclient connection.
I create a tcpclient connection:
t = tcpclient(‘address’, port);
And I send a request to the server (which starts automatically to send data):
write( t, ‘request’ );
I want to have a callback function triggered by a bytes available event:
configureCallback( t, "terminator", @MyCallbackFcn );
MyCallbackFcn is written in a separated MyCallbackFcn.m file. The callback function MyCallbackFcn is triggeredd whenever a terminator is available to be read from the remote host specified by the TCP/IP client.
At the moment, MyCallbackFcn uses global parameters (var1, var2, etc.) defined in the main program:
function MyCallbackFcn( src, ~ )
global var1 var2
…
end
This algorithm works well. But in order to avoid the use of global parameters, I would like to define input parameters for MyCallbackFcn fonction. My problems start here, because I do not find the right form to write:
the definition of the callback function in the main program : configureCallback( t,…
the function MyCallbackFcn in the MyCallbackFcn.m file
Thank you in advance for your help.
Raphaël Hy all,
my problem concerns the use of input arguments when I define the BytesAvailableFcn of a tcpclient connection.
I create a tcpclient connection:
t = tcpclient(‘address’, port);
And I send a request to the server (which starts automatically to send data):
write( t, ‘request’ );
I want to have a callback function triggered by a bytes available event:
configureCallback( t, "terminator", @MyCallbackFcn );
MyCallbackFcn is written in a separated MyCallbackFcn.m file. The callback function MyCallbackFcn is triggeredd whenever a terminator is available to be read from the remote host specified by the TCP/IP client.
At the moment, MyCallbackFcn uses global parameters (var1, var2, etc.) defined in the main program:
function MyCallbackFcn( src, ~ )
global var1 var2
…
end
This algorithm works well. But in order to avoid the use of global parameters, I would like to define input parameters for MyCallbackFcn fonction. My problems start here, because I do not find the right form to write:
the definition of the callback function in the main program : configureCallback( t,…
the function MyCallbackFcn in the MyCallbackFcn.m file
Thank you in advance for your help.
Raphaël tcpclient, bytesavailablefcn, input parameters MATLAB Answers — New Questions
MATLAB Coder: C Version Much Slower Than Mex Version
I used MATLAB Coder to turn my MATLAB code into C code and expected a great decrease in run time, but instead found that my C code runs much slower than both the MATLAB code and the mex code. Over 5 tests, I get the following:
Tthe MATLAB code took 77.48 seconds on average.
The mex version running in MATLAB took 46.27 seconds on average.
The generated C code took 262.35 seconds on average.
All three versions of the code produces the exact same output, so I am confident that each version is working properly. I am running the MATLAB and mex versions in R2023a and the C version in Debian 11 (bullseye) in a docker container. The cmake command I am running is
cmake -DCMAKE_BUILD_TYPE=Release ..
and my understanding is that this enables the C compiler optimisations, but I’m unsure if there are further optimisations I can enable. Before specifying the build type as release, my C code ran about 90 seconds slower still (~350s), which is horrendous compared to the MATLAB/mex version.
These are the settings I am generating my code with:
The full settings I used are attached in config.mat but they are almost all just the default settings.
My understanding is that MATLAB does some computations in parallel automatically, while the generated C code doesn’t, so I tried turning on automatic parallelisation in the generated code. This only made the code run slower, however. I’m not sure how the automatic paralellisation works, but when I manually tried to parallelise parts of my code, it also did not run faster, so I did not really expect this to improve anything.
I’m just really unsure why the C version runs so much slower than even the mex version, which I expected to be similar or worse than the C version. Are there settings I can tweak in Coder? Are there further optimisations I can enable on the Linux side of things? If this is normal behaviour, what is the explanation for the discrepency between C and mex?I used MATLAB Coder to turn my MATLAB code into C code and expected a great decrease in run time, but instead found that my C code runs much slower than both the MATLAB code and the mex code. Over 5 tests, I get the following:
Tthe MATLAB code took 77.48 seconds on average.
The mex version running in MATLAB took 46.27 seconds on average.
The generated C code took 262.35 seconds on average.
All three versions of the code produces the exact same output, so I am confident that each version is working properly. I am running the MATLAB and mex versions in R2023a and the C version in Debian 11 (bullseye) in a docker container. The cmake command I am running is
cmake -DCMAKE_BUILD_TYPE=Release ..
and my understanding is that this enables the C compiler optimisations, but I’m unsure if there are further optimisations I can enable. Before specifying the build type as release, my C code ran about 90 seconds slower still (~350s), which is horrendous compared to the MATLAB/mex version.
These are the settings I am generating my code with:
The full settings I used are attached in config.mat but they are almost all just the default settings.
My understanding is that MATLAB does some computations in parallel automatically, while the generated C code doesn’t, so I tried turning on automatic parallelisation in the generated code. This only made the code run slower, however. I’m not sure how the automatic paralellisation works, but when I manually tried to parallelise parts of my code, it also did not run faster, so I did not really expect this to improve anything.
I’m just really unsure why the C version runs so much slower than even the mex version, which I expected to be similar or worse than the C version. Are there settings I can tweak in Coder? Are there further optimisations I can enable on the Linux side of things? If this is normal behaviour, what is the explanation for the discrepency between C and mex? I used MATLAB Coder to turn my MATLAB code into C code and expected a great decrease in run time, but instead found that my C code runs much slower than both the MATLAB code and the mex code. Over 5 tests, I get the following:
Tthe MATLAB code took 77.48 seconds on average.
The mex version running in MATLAB took 46.27 seconds on average.
The generated C code took 262.35 seconds on average.
All three versions of the code produces the exact same output, so I am confident that each version is working properly. I am running the MATLAB and mex versions in R2023a and the C version in Debian 11 (bullseye) in a docker container. The cmake command I am running is
cmake -DCMAKE_BUILD_TYPE=Release ..
and my understanding is that this enables the C compiler optimisations, but I’m unsure if there are further optimisations I can enable. Before specifying the build type as release, my C code ran about 90 seconds slower still (~350s), which is horrendous compared to the MATLAB/mex version.
These are the settings I am generating my code with:
The full settings I used are attached in config.mat but they are almost all just the default settings.
My understanding is that MATLAB does some computations in parallel automatically, while the generated C code doesn’t, so I tried turning on automatic parallelisation in the generated code. This only made the code run slower, however. I’m not sure how the automatic paralellisation works, but when I manually tried to parallelise parts of my code, it also did not run faster, so I did not really expect this to improve anything.
I’m just really unsure why the C version runs so much slower than even the mex version, which I expected to be similar or worse than the C version. Are there settings I can tweak in Coder? Are there further optimisations I can enable on the Linux side of things? If this is normal behaviour, what is the explanation for the discrepency between C and mex? gcc, mex, optimisation, optimization, linux, cmake MATLAB Answers — New Questions
Add 3 to just the odd-index elements
I am using this help-yourself
http://www.facstaff.bucknell.edu/maneval/help211/exercises.html
And have a question regarding
2. Let x = [2 5 1 6].
b. Add 3 to just the odd-index elements
They give the answer as
b = x(1:2:end) + 3
but that makes a new matrix with just two numbers in it.
Like so:
"b =
21 20
"
Is the question or the answer wrong?I am using this help-yourself
http://www.facstaff.bucknell.edu/maneval/help211/exercises.html
And have a question regarding
2. Let x = [2 5 1 6].
b. Add 3 to just the odd-index elements
They give the answer as
b = x(1:2:end) + 3
but that makes a new matrix with just two numbers in it.
Like so:
"b =
21 20
"
Is the question or the answer wrong? I am using this help-yourself
http://www.facstaff.bucknell.edu/maneval/help211/exercises.html
And have a question regarding
2. Let x = [2 5 1 6].
b. Add 3 to just the odd-index elements
They give the answer as
b = x(1:2:end) + 3
but that makes a new matrix with just two numbers in it.
Like so:
"b =
21 20
"
Is the question or the answer wrong? odd matrix numbers MATLAB Answers — New Questions
How do I install Statistics and Machine Learning Toolbox into an existing installation of MATLAB?
I have called one function in which random is used but an error comes up ‘random’ requires Statistics and Machine Learning Toolbox. I click on this link and it asks to install it. I click on it and I see this window "Your administrator has restricted your download access to this MathWorks product".I have called one function in which random is used but an error comes up ‘random’ requires Statistics and Machine Learning Toolbox. I click on this link and it asks to install it. I click on it and I see this window "Your administrator has restricted your download access to this MathWorks product". I have called one function in which random is used but an error comes up ‘random’ requires Statistics and Machine Learning Toolbox. I click on this link and it asks to install it. I click on it and I see this window "Your administrator has restricted your download access to this MathWorks product". statistics, machine, learning toolbox MATLAB Answers — New Questions
Battery Pack Modeling – Self-Paced Online Course – Unable to Proceed Further due to Problem in Task 4 in the exercise “Exploring the Custom Battery Pack Block”
Hello, I have recently started learning about Battery Pack Modelling using Simulink/Simscape through the "Battery Pack Modelling" Self-Paced Online Course offered by MathWorks. I am taking the course through the Chrome Browser (Simulink Online) for the simulinkR2024b version.
Presently, I am facing an issue under Section 2.1 – Pack Modelling of this course due to which my progress has come to a halt. The problem I am experiencing is related to Task 4 in the exercise "Exploring the Custom Battery Pack Block" of the particular section I mentioned above. I am unable to proceed ahead with the completion of the exercise as the "Training Assessment" fails each and every time I click the submit button even though I have clearly and carefully followed the instructions provided and completed the given task.
To give a brief summary and clarify the context, in Task 4, we have to observe the battery voltages in the simulation. We have to start by right-clicking the batteryVoltage port of the Battery Pack and selecting Log Selected Signals. Next, we have to change the Stop Time in the Simulate section to 200. After that, we have to navigate to the Simulation tab and click Run to execute the model. Once the simulation is complete, we have to access the Data Inspector from the Review Results section. The Simulation Data Inspector window appears, and we have to click and select NewPack(8). A dialog box titled Multidimensional Signal appears, where we have to select Convert to channels (24) and then choose NewPack (1,1) and NewPack (10,1) to view the battery voltages.
Now the difficulty I encountered while performing the task is that after running the simulation and opening up Data Inspector from the Review Results section, I am not shown the option of NewPack(8) as mentioned in the instructions and instead shown NewPack:3 (8). Also, when I click and select NewPack:3 (8), I am not presented with the option of Convert to channels (24) and instead presented with Convert to channels (8). As a result, there are no options such as NewPack (1,1) and NewPack (10,1) to select in order to observe the battery voltages. I believe the "Training Assessment" fails when I click submit because I don’t meet the criteria specified in the instructions. However, despite re-running the task multiple times, I consistently receive the same set of options to select, not the ones specified in the task instructions. Hence, I am unable to proceed further.
Could someone verify whether there are any problems with the assessment or the proposed solution?
I have attached screenshots for reference.Hello, I have recently started learning about Battery Pack Modelling using Simulink/Simscape through the "Battery Pack Modelling" Self-Paced Online Course offered by MathWorks. I am taking the course through the Chrome Browser (Simulink Online) for the simulinkR2024b version.
Presently, I am facing an issue under Section 2.1 – Pack Modelling of this course due to which my progress has come to a halt. The problem I am experiencing is related to Task 4 in the exercise "Exploring the Custom Battery Pack Block" of the particular section I mentioned above. I am unable to proceed ahead with the completion of the exercise as the "Training Assessment" fails each and every time I click the submit button even though I have clearly and carefully followed the instructions provided and completed the given task.
To give a brief summary and clarify the context, in Task 4, we have to observe the battery voltages in the simulation. We have to start by right-clicking the batteryVoltage port of the Battery Pack and selecting Log Selected Signals. Next, we have to change the Stop Time in the Simulate section to 200. After that, we have to navigate to the Simulation tab and click Run to execute the model. Once the simulation is complete, we have to access the Data Inspector from the Review Results section. The Simulation Data Inspector window appears, and we have to click and select NewPack(8). A dialog box titled Multidimensional Signal appears, where we have to select Convert to channels (24) and then choose NewPack (1,1) and NewPack (10,1) to view the battery voltages.
Now the difficulty I encountered while performing the task is that after running the simulation and opening up Data Inspector from the Review Results section, I am not shown the option of NewPack(8) as mentioned in the instructions and instead shown NewPack:3 (8). Also, when I click and select NewPack:3 (8), I am not presented with the option of Convert to channels (24) and instead presented with Convert to channels (8). As a result, there are no options such as NewPack (1,1) and NewPack (10,1) to select in order to observe the battery voltages. I believe the "Training Assessment" fails when I click submit because I don’t meet the criteria specified in the instructions. However, despite re-running the task multiple times, I consistently receive the same set of options to select, not the ones specified in the task instructions. Hence, I am unable to proceed further.
Could someone verify whether there are any problems with the assessment or the proposed solution?
I have attached screenshots for reference. Hello, I have recently started learning about Battery Pack Modelling using Simulink/Simscape through the "Battery Pack Modelling" Self-Paced Online Course offered by MathWorks. I am taking the course through the Chrome Browser (Simulink Online) for the simulinkR2024b version.
Presently, I am facing an issue under Section 2.1 – Pack Modelling of this course due to which my progress has come to a halt. The problem I am experiencing is related to Task 4 in the exercise "Exploring the Custom Battery Pack Block" of the particular section I mentioned above. I am unable to proceed ahead with the completion of the exercise as the "Training Assessment" fails each and every time I click the submit button even though I have clearly and carefully followed the instructions provided and completed the given task.
To give a brief summary and clarify the context, in Task 4, we have to observe the battery voltages in the simulation. We have to start by right-clicking the batteryVoltage port of the Battery Pack and selecting Log Selected Signals. Next, we have to change the Stop Time in the Simulate section to 200. After that, we have to navigate to the Simulation tab and click Run to execute the model. Once the simulation is complete, we have to access the Data Inspector from the Review Results section. The Simulation Data Inspector window appears, and we have to click and select NewPack(8). A dialog box titled Multidimensional Signal appears, where we have to select Convert to channels (24) and then choose NewPack (1,1) and NewPack (10,1) to view the battery voltages.
Now the difficulty I encountered while performing the task is that after running the simulation and opening up Data Inspector from the Review Results section, I am not shown the option of NewPack(8) as mentioned in the instructions and instead shown NewPack:3 (8). Also, when I click and select NewPack:3 (8), I am not presented with the option of Convert to channels (24) and instead presented with Convert to channels (8). As a result, there are no options such as NewPack (1,1) and NewPack (10,1) to select in order to observe the battery voltages. I believe the "Training Assessment" fails when I click submit because I don’t meet the criteria specified in the instructions. However, despite re-running the task multiple times, I consistently receive the same set of options to select, not the ones specified in the task instructions. Hence, I am unable to proceed further.
Could someone verify whether there are any problems with the assessment or the proposed solution?
I have attached screenshots for reference. battery pack modelling, self-paced online course, simscape, simulink MATLAB Answers — New Questions
在win11上运行matlabR2022b的实时仿真遇到错误
simulink运行real-time syn时报错
‘untitled/Real-Time Synchronization’ 中的 S-Function ‘sldrtsync’ 报告错误: Hardware timer cannot be allocated. Real-time kernel cannot run.
目前在网上没有找到解决方案,求问该如何解决
ps:在这之前有报错和hyper-v冲突,将hyper-v手动停止运行后就出现了上述错误simulink运行real-time syn时报错
‘untitled/Real-Time Synchronization’ 中的 S-Function ‘sldrtsync’ 报告错误: Hardware timer cannot be allocated. Real-time kernel cannot run.
目前在网上没有找到解决方案,求问该如何解决
ps:在这之前有报错和hyper-v冲突,将hyper-v手动停止运行后就出现了上述错误 simulink运行real-time syn时报错
‘untitled/Real-Time Synchronization’ 中的 S-Function ‘sldrtsync’ 报告错误: Hardware timer cannot be allocated. Real-time kernel cannot run.
目前在网上没有找到解决方案,求问该如何解决
ps:在这之前有报错和hyper-v冲突,将hyper-v手动停止运行后就出现了上述错误 simulink, 实时仿真, real-time syn MATLAB Answers — New Questions
Using a variable in an input prompt
I am trying to use the iterator (ii) of my for loop as a string in my input prompt. The code is shown below
for ii = 1:n
x = input(‘What is the orientation of molecule ‘ num2str(ii) ‘in the x-direction?’);
end
but this does not work. Any suggestions?I am trying to use the iterator (ii) of my for loop as a string in my input prompt. The code is shown below
for ii = 1:n
x = input(‘What is the orientation of molecule ‘ num2str(ii) ‘in the x-direction?’);
end
but this does not work. Any suggestions? I am trying to use the iterator (ii) of my for loop as a string in my input prompt. The code is shown below
for ii = 1:n
x = input(‘What is the orientation of molecule ‘ num2str(ii) ‘in the x-direction?’);
end
but this does not work. Any suggestions? input, prompt, for MATLAB Answers — New Questions
Adjusting sample rate in Simulink model to reflect transition from bitrate to symbol rate
I am trying to build a simple communication system in Simulink. I want to simulate a bit source that generates bits with a specific sample rate (bit rate). I then buffer the generate samples into frames of 1008 bits. For application specific reasons I then pad the frame with 16 zeros to a total of 1024 bits. The goal is then to BPSK modulate the bits and output the generated symbols at a specific symbol rate different to the bit rate.
The goal is that the spectrum analyzer shows a spectrum that reflects the intended symbol rate.
I have problems implementing this and I am confused about how Simulink handles frame time/sample time. Sample time in Simulink is defined as the rate at which a block generates output. So far so good, but I still want to enforce a specfic real sample time, i.e., time between consecutive samples (NOT frames).
Problem 1
Using the Vector Concatenate block for zero padding effectively seems to upsample the signal and the sample time in the resulting frame is smaller than the bitrate/sample rate specified in the bit source. I am using a Frame Transition block to remedy this where I specify the sample time (this is ambigous this specifies the frame time due to the Simulink sample time definition) property as (Frame_Size+16)*bit_rate. This does not seem to work as the output frames of the Rate Transition block is somewhat unpredictable. However, when placing a spectrum analyzer directly after the first Rate Transition block, the sample rate that is displayed in the spectrum analyzer shows the intended sample rate = bit_rate (10 kHz).
Problem 2
After the BPSK block I placed another Rate Transition Block to generate symbol frames where each symbol is output at a specific symbol rate. In my case the symbol rate is bit_rate/10. The spectrum analyzer shows the desired sample rate (1kHz). (see image below)
BUT: again, the output frames of the second Rate Transition block do not show the desired behaviour. I want it to buffer the incoming frames and output them at a slower rate. What happens though, is that the Rate Transition block subsamples the input and outputs every 10th frame and drops the other frames.
Any help is greatly appreciated! Thanks!I am trying to build a simple communication system in Simulink. I want to simulate a bit source that generates bits with a specific sample rate (bit rate). I then buffer the generate samples into frames of 1008 bits. For application specific reasons I then pad the frame with 16 zeros to a total of 1024 bits. The goal is then to BPSK modulate the bits and output the generated symbols at a specific symbol rate different to the bit rate.
The goal is that the spectrum analyzer shows a spectrum that reflects the intended symbol rate.
I have problems implementing this and I am confused about how Simulink handles frame time/sample time. Sample time in Simulink is defined as the rate at which a block generates output. So far so good, but I still want to enforce a specfic real sample time, i.e., time between consecutive samples (NOT frames).
Problem 1
Using the Vector Concatenate block for zero padding effectively seems to upsample the signal and the sample time in the resulting frame is smaller than the bitrate/sample rate specified in the bit source. I am using a Frame Transition block to remedy this where I specify the sample time (this is ambigous this specifies the frame time due to the Simulink sample time definition) property as (Frame_Size+16)*bit_rate. This does not seem to work as the output frames of the Rate Transition block is somewhat unpredictable. However, when placing a spectrum analyzer directly after the first Rate Transition block, the sample rate that is displayed in the spectrum analyzer shows the intended sample rate = bit_rate (10 kHz).
Problem 2
After the BPSK block I placed another Rate Transition Block to generate symbol frames where each symbol is output at a specific symbol rate. In my case the symbol rate is bit_rate/10. The spectrum analyzer shows the desired sample rate (1kHz). (see image below)
BUT: again, the output frames of the second Rate Transition block do not show the desired behaviour. I want it to buffer the incoming frames and output them at a slower rate. What happens though, is that the Rate Transition block subsamples the input and outputs every 10th frame and drops the other frames.
Any help is greatly appreciated! Thanks! I am trying to build a simple communication system in Simulink. I want to simulate a bit source that generates bits with a specific sample rate (bit rate). I then buffer the generate samples into frames of 1008 bits. For application specific reasons I then pad the frame with 16 zeros to a total of 1024 bits. The goal is then to BPSK modulate the bits and output the generated symbols at a specific symbol rate different to the bit rate.
The goal is that the spectrum analyzer shows a spectrum that reflects the intended symbol rate.
I have problems implementing this and I am confused about how Simulink handles frame time/sample time. Sample time in Simulink is defined as the rate at which a block generates output. So far so good, but I still want to enforce a specfic real sample time, i.e., time between consecutive samples (NOT frames).
Problem 1
Using the Vector Concatenate block for zero padding effectively seems to upsample the signal and the sample time in the resulting frame is smaller than the bitrate/sample rate specified in the bit source. I am using a Frame Transition block to remedy this where I specify the sample time (this is ambigous this specifies the frame time due to the Simulink sample time definition) property as (Frame_Size+16)*bit_rate. This does not seem to work as the output frames of the Rate Transition block is somewhat unpredictable. However, when placing a spectrum analyzer directly after the first Rate Transition block, the sample rate that is displayed in the spectrum analyzer shows the intended sample rate = bit_rate (10 kHz).
Problem 2
After the BPSK block I placed another Rate Transition Block to generate symbol frames where each symbol is output at a specific symbol rate. In my case the symbol rate is bit_rate/10. The spectrum analyzer shows the desired sample rate (1kHz). (see image below)
BUT: again, the output frames of the second Rate Transition block do not show the desired behaviour. I want it to buffer the incoming frames and output them at a slower rate. What happens though, is that the Rate Transition block subsamples the input and outputs every 10th frame and drops the other frames.
Any help is greatly appreciated! Thanks! simulink, sample time, rate transition, symbol rate, bit rate MATLAB Answers — New Questions
Why can’t we define properties on enumerations extending from built-in classes?
Trying to understand why we can’t subclass something like a uint8 and add a property. Say I want to enumerate data types and conveniently bundle the size of instances of the type in bytes.
In this first case, we specify which uint8 we want each enumeration member to correspond to in parens next to the name, and this works fine:
classdef DataTypeEnumeration < uint8
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
end
In totally user-defined classes we use these parens to set properties, like
classdef DataTypeEnumeration
properties
underlying_value
end
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
methods
function obj = DataTypeEnumeration(v)
obj.underlying_value = v
end
end
end
but it does not seem there is any way to use this syntax for the built-in type, even if I am not actually trying to define a new property:
classdef DataTypeEnumeration < uint8
properties
some_special_underlying_value_property
end
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
methods
function obj = DataTypeEnumeration(v)
obj.some_special_underlying_value_property = uint8(v)
end
end
end
or even just
classdef DataTypeEnumeration < uint8
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
methods
function obj = DataTypeEnumeration(v)
obj = uint8(v)
end
end
end
seems like it should work. It kind of feels like the only reason we can’t tack on a property to an enumeration of some built-in type is because the interface doesn’t support it, which would be sad. What would be the harm in being able to let the parent object be constructed with the first argument and set properties with following arguments, like
classdef DataTypeEnumeration < uint8
properties
bytes
end
enumeration
UINT8 (0, 1)
UINT16 (1, 2)
UINT32 (2, 4)
UINT64 (3, 8)
end
methods
function obj = DataTypeEnumeration(b)
obj.bytes = b
end
end
endTrying to understand why we can’t subclass something like a uint8 and add a property. Say I want to enumerate data types and conveniently bundle the size of instances of the type in bytes.
In this first case, we specify which uint8 we want each enumeration member to correspond to in parens next to the name, and this works fine:
classdef DataTypeEnumeration < uint8
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
end
In totally user-defined classes we use these parens to set properties, like
classdef DataTypeEnumeration
properties
underlying_value
end
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
methods
function obj = DataTypeEnumeration(v)
obj.underlying_value = v
end
end
end
but it does not seem there is any way to use this syntax for the built-in type, even if I am not actually trying to define a new property:
classdef DataTypeEnumeration < uint8
properties
some_special_underlying_value_property
end
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
methods
function obj = DataTypeEnumeration(v)
obj.some_special_underlying_value_property = uint8(v)
end
end
end
or even just
classdef DataTypeEnumeration < uint8
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
methods
function obj = DataTypeEnumeration(v)
obj = uint8(v)
end
end
end
seems like it should work. It kind of feels like the only reason we can’t tack on a property to an enumeration of some built-in type is because the interface doesn’t support it, which would be sad. What would be the harm in being able to let the parent object be constructed with the first argument and set properties with following arguments, like
classdef DataTypeEnumeration < uint8
properties
bytes
end
enumeration
UINT8 (0, 1)
UINT16 (1, 2)
UINT32 (2, 4)
UINT64 (3, 8)
end
methods
function obj = DataTypeEnumeration(b)
obj.bytes = b
end
end
end Trying to understand why we can’t subclass something like a uint8 and add a property. Say I want to enumerate data types and conveniently bundle the size of instances of the type in bytes.
In this first case, we specify which uint8 we want each enumeration member to correspond to in parens next to the name, and this works fine:
classdef DataTypeEnumeration < uint8
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
end
In totally user-defined classes we use these parens to set properties, like
classdef DataTypeEnumeration
properties
underlying_value
end
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
methods
function obj = DataTypeEnumeration(v)
obj.underlying_value = v
end
end
end
but it does not seem there is any way to use this syntax for the built-in type, even if I am not actually trying to define a new property:
classdef DataTypeEnumeration < uint8
properties
some_special_underlying_value_property
end
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
methods
function obj = DataTypeEnumeration(v)
obj.some_special_underlying_value_property = uint8(v)
end
end
end
or even just
classdef DataTypeEnumeration < uint8
enumeration
UINT8 (0)
UINT16 (1)
UINT32 (2)
UINT64 (3)
end
methods
function obj = DataTypeEnumeration(v)
obj = uint8(v)
end
end
end
seems like it should work. It kind of feels like the only reason we can’t tack on a property to an enumeration of some built-in type is because the interface doesn’t support it, which would be sad. What would be the harm in being able to let the parent object be constructed with the first argument and set properties with following arguments, like
classdef DataTypeEnumeration < uint8
properties
bytes
end
enumeration
UINT8 (0, 1)
UINT16 (1, 2)
UINT32 (2, 4)
UINT64 (3, 8)
end
methods
function obj = DataTypeEnumeration(b)
obj.bytes = b
end
end
end enumeration, subclass, built-in, properties MATLAB Answers — New Questions
How can I determine the angle between two vectors in MATLAB?
How can I determine the angle between two vectors in MATLAB?
I have two vectors. Is there a MATLAB function that can determine the angle between them?How can I determine the angle between two vectors in MATLAB?
I have two vectors. Is there a MATLAB function that can determine the angle between them? How can I determine the angle between two vectors in MATLAB?
I have two vectors. Is there a MATLAB function that can determine the angle between them? angle, vectors, dot, theta MATLAB Answers — New Questions