Tag Archives: matlab
Why does the value of “PRBSetType — PRB allocation type” change to (VRB) through code even if I set it as (PRB) in the configuration?
Why does the value of "PRBSetType — PRB allocation type" change to (VRB) through code even if I set it as (PRB) in the configuration?
Specifically, "getPXSCHobject" function doesn’t read the input value of "PRBSetType — PRB allocation type" and always sets it by default value (VRB).
And as a result, code always go through one case of the two possible cases -PRBsetType = VRB-, so we can’t get the results when we want to set PRBsetType as (PRB).
The two possible cases are inserted below:
Case 1: PRBsetType = PRB
Case 2: PRBsetType = VRBWhy does the value of "PRBSetType — PRB allocation type" change to (VRB) through code even if I set it as (PRB) in the configuration?
Specifically, "getPXSCHobject" function doesn’t read the input value of "PRBSetType — PRB allocation type" and always sets it by default value (VRB).
And as a result, code always go through one case of the two possible cases -PRBsetType = VRB-, so we can’t get the results when we want to set PRBsetType as (PRB).
The two possible cases are inserted below:
Case 1: PRBsetType = PRB
Case 2: PRBsetType = VRB Why does the value of "PRBSetType — PRB allocation type" change to (VRB) through code even if I set it as (PRB) in the configuration?
Specifically, "getPXSCHobject" function doesn’t read the input value of "PRBSetType — PRB allocation type" and always sets it by default value (VRB).
And as a result, code always go through one case of the two possible cases -PRBsetType = VRB-, so we can’t get the results when we want to set PRBsetType as (PRB).
The two possible cases are inserted below:
Case 1: PRBsetType = PRB
Case 2: PRBsetType = VRB 5g, 5g toolbox, vrbinterleaving MATLAB Answers — New Questions
Average code length and entropy
Hello,
I have an uin16 vector and I got the Huffman code from the built-in functions in MATLAB. The thing is that the entropy of this file is different from the average code length that I’ve got from the Huffman code. Isn’t the average code length supposed to be equal to the entropy of the file?
Thanks.Hello,
I have an uin16 vector and I got the Huffman code from the built-in functions in MATLAB. The thing is that the entropy of this file is different from the average code length that I’ve got from the Huffman code. Isn’t the average code length supposed to be equal to the entropy of the file?
Thanks. Hello,
I have an uin16 vector and I got the Huffman code from the built-in functions in MATLAB. The thing is that the entropy of this file is different from the average code length that I’ve got from the Huffman code. Isn’t the average code length supposed to be equal to the entropy of the file?
Thanks. huffman, average code length, entropy MATLAB Answers — New Questions
Function to capitalize first letter in each word in string but forces all other letters to be lowercase
Does anyone know how to create a function which accepts a string and capitalizes the first letter in each word of the string, but also forces the other letters to be lowercase?
Any advice would be greatly appreciated!!
This is my attempt so far:
str=[‘this is a TEST’];
for i=1:length(str);
if str(1,i(1));
str= upper(str);
else str(1,i);
str= lower(str);
end
endDoes anyone know how to create a function which accepts a string and capitalizes the first letter in each word of the string, but also forces the other letters to be lowercase?
Any advice would be greatly appreciated!!
This is my attempt so far:
str=[‘this is a TEST’];
for i=1:length(str);
if str(1,i(1));
str= upper(str);
else str(1,i);
str= lower(str);
end
end Does anyone know how to create a function which accepts a string and capitalizes the first letter in each word of the string, but also forces the other letters to be lowercase?
Any advice would be greatly appreciated!!
This is my attempt so far:
str=[‘this is a TEST’];
for i=1:length(str);
if str(1,i(1));
str= upper(str);
else str(1,i);
str= lower(str);
end
end matlab, function, uppercase, live script MATLAB Answers — New Questions
error in task 6 of robotic vacuum stateflow
says that the transition is not correct, but is the same as the solutionsays that the transition is not correct, but is the same as the solution says that the transition is not correct, but is the same as the solution stateflow, task 6, robotic vacuum MATLAB Answers — New Questions
Extract only diagonal elements from matrix
I have a matrix in one variable and a list of coordinates in another variable. Is there a way to extract only the matching pairs of coordinate from the matrix? I.e. X(1),Y(1); X(2), Y(2)…
I can extract all of the permutations (X1, Y1; X1 Y2 …X2,Y1 … etc) and then take the diagonal, but I was wondering if there was a simple solution I’m missing to only extract the matched pairs.
Thanks,
Will
%Data
mat = rand(100);
%Coordinates
x_coord = round(rand(10,1)*100);
y_coord = round(rand(10,1)*100);
%Extract coordinates
extracted_coord = diag(mat(x_coord,y_coord));I have a matrix in one variable and a list of coordinates in another variable. Is there a way to extract only the matching pairs of coordinate from the matrix? I.e. X(1),Y(1); X(2), Y(2)…
I can extract all of the permutations (X1, Y1; X1 Y2 …X2,Y1 … etc) and then take the diagonal, but I was wondering if there was a simple solution I’m missing to only extract the matched pairs.
Thanks,
Will
%Data
mat = rand(100);
%Coordinates
x_coord = round(rand(10,1)*100);
y_coord = round(rand(10,1)*100);
%Extract coordinates
extracted_coord = diag(mat(x_coord,y_coord)); I have a matrix in one variable and a list of coordinates in another variable. Is there a way to extract only the matching pairs of coordinate from the matrix? I.e. X(1),Y(1); X(2), Y(2)…
I can extract all of the permutations (X1, Y1; X1 Y2 …X2,Y1 … etc) and then take the diagonal, but I was wondering if there was a simple solution I’m missing to only extract the matched pairs.
Thanks,
Will
%Data
mat = rand(100);
%Coordinates
x_coord = round(rand(10,1)*100);
y_coord = round(rand(10,1)*100);
%Extract coordinates
extracted_coord = diag(mat(x_coord,y_coord)); matrix manipulation, indexing MATLAB Answers — New Questions
how to set initial signal out from relay simulink
Hello all, Paul @Stephen23
I have simulink model with relay bock.
this relay block switch on when the value reach 100 and the output signal is 1 and switch off when reach 20 and the output signal is 0.
my problem is that the relay initial output is always off, this means when the initial value is for example 44 the out out is 0.
but in some cases I want to be my initial output is on (1)
How can i change the initial output signal?
best regards, AhmadHello all, Paul @Stephen23
I have simulink model with relay bock.
this relay block switch on when the value reach 100 and the output signal is 1 and switch off when reach 20 and the output signal is 0.
my problem is that the relay initial output is always off, this means when the initial value is for example 44 the out out is 0.
but in some cases I want to be my initial output is on (1)
How can i change the initial output signal?
best regards, Ahmad Hello all, Paul @Stephen23
I have simulink model with relay bock.
this relay block switch on when the value reach 100 and the output signal is 1 and switch off when reach 20 and the output signal is 0.
my problem is that the relay initial output is always off, this means when the initial value is for example 44 the out out is 0.
but in some cases I want to be my initial output is on (1)
How can i change the initial output signal?
best regards, Ahmad relay block MATLAB Answers — New Questions
boxchart – different box width according to number of data points
Hi,
I am looking for a way to set the width of a boxplot according to the number of datapoints within a boxchart.
See attachet an example how it looks like in R. When I try this in matlab, I get an error, because matlab accepts only scalars and no vectors. I would prefer to do all my statistics with matlab, so this function would be very helpful.
Thank you
MarkusHi,
I am looking for a way to set the width of a boxplot according to the number of datapoints within a boxchart.
See attachet an example how it looks like in R. When I try this in matlab, I get an error, because matlab accepts only scalars and no vectors. I would prefer to do all my statistics with matlab, so this function would be very helpful.
Thank you
Markus Hi,
I am looking for a way to set the width of a boxplot according to the number of datapoints within a boxchart.
See attachet an example how it looks like in R. When I try this in matlab, I get an error, because matlab accepts only scalars and no vectors. I would prefer to do all my statistics with matlab, so this function would be very helpful.
Thank you
Markus boxchart, width of box MATLAB Answers — New Questions
Why doesn’t the figure show the text and fitting line?
Text in the left corner and fitting line is missing from my fiures, please make correction to my code:
% Define heights, FOVs, and SNR values to test
heights = [1000, 2000, 3000, 4000];
fovs = [0.2, 0.5, 1, 2, 5, 10];
snr_values = [0, 25, 50, 75, 100];
% Function to calculate performance metrics
calculate_r_squared = @(x, y) 1 – sum((y – x).^2) / sum((y – mean(y)).^2);
calculate_rmse = @(x, y) sqrt(mean((y – x).^2));
calculate_mape = @(x, y) mean(abs((y – x) ./ y)) * 100;
calculate_mae = @(x, y) mean(abs(y – x));
calculate_made = @(x, y) mean(abs(y – mean(x)));
% Initialize arrays to store performance metrics
performance_metrics = struct();
% Loop over height values
for h = heights
% Filter the data for the current height
idx = (lookup_table(:, 1) == h);
data_filtered = lookup_table(idx, :);
% Initialize arrays to store performance metrics for each FOV and SNR value
performance_metrics(h).r_squared_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).rmse_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).mape_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).mae_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).made_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).r_squared_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).rmse_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).mape_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).mae_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).made_a = zeros(length(fovs), length(snr_values));
% Plot optimal_r_input vs. optimal_r_interp
figure;
hold on;
colors = jet(length(fovs) * length(snr_values));
c_idx = 1;
for fov_idx = 1:length(fovs)
for snr_idx = 1:length(snr_values)
fov = fovs(fov_idx);
snr = snr_values(snr_idx);
% Filter data for the current FOV and SNR
idx_fov_snr = (data_filtered(:, 2) == fov) & (data_filtered(:, 3) == snr);
optimal_r_input = data_filtered(idx_fov_snr, 4);
optimal_r_interp = data_filtered(idx_fov_snr, 5);
% Scatter plot
if ~isempty(optimal_r_input)
scatter(optimal_r_input, optimal_r_interp, 50, colors(c_idx, :), ‘filled’);
% Fit and plot linear regression line if there is sufficient data
if length(optimal_r_input) > 1
model_r = fitlm(optimal_r_input, optimal_r_interp);
plot(model_r.Variables.x1, model_r.Fitted, ‘Color’, colors(c_idx, :), ‘LineWidth’, 2);
% Calculate additional performance metrics
r_squared_r = model_r.Rsquared.Ordinary;
rmse_r = calculate_rmse(optimal_r_input, optimal_r_interp);
mape_r = calculate_mape(optimal_r_input, optimal_r_interp);
mae_r = calculate_mae(optimal_r_input, optimal_r_interp);
made_r = calculate_made(optimal_r_input, optimal_r_interp);
% Store the performance metrics for this FOV and SNR value
performance_metrics(h).r_squared_r(fov_idx, snr_idx) = r_squared_r;
performance_metrics(h).rmse_r(fov_idx, snr_idx) = rmse_r;
performance_metrics(h).mape_r(fov_idx, snr_idx) = mape_r;
performance_metrics(h).mae_r(fov_idx, snr_idx) = mae_r;
performance_metrics(h).made_r(fov_idx, snr_idx) = made_r;
% Display text with performance metrics
text(mean(optimal_r_input), mean(optimal_r_interp), …
{[‘SNR = ‘, num2str(snr), ‘ dB’], …
[‘R^2 = ‘, num2str(r_squared_r)], …
[‘RMSE = ‘, num2str(rmse_r)], …
[‘MAPE = ‘, num2str(mape_r), ‘%’], …
[‘MAE = ‘, num2str(mae_r)], …
[‘MADE = ‘, num2str(made_r)]}, …
‘FontSize’, 10, ‘Color’, colors(c_idx, :));
end
end
c_idx = c_idx + 1;
end
end
xlabel(‘Optimal R_{e} (mum)’);
ylabel(‘Optimal R_{e} interp (mum)’);
title([‘Plot of optimal R_{e} and optimal R_{e} interp for Height = ‘, num2str(h)]);
grid on;
hold off;
% Plot optimal_a_input vs. optimal_a_interp
figure;
hold on;
c_idx = 1;
for fov_idx = 1:length(fovs)
for snr_idx = 1:length(snr_values)
fov = fovs(fov_idx);
snr = snr_values(snr_idx);
% Filter data for the current FOV and SNR
idx_fov_snr = (data_filtered(:, 2) == fov) & (data_filtered(:, 3) == snr);
optimal_a_input = data_filtered(idx_fov_snr, 6);
optimal_a_interp = data_filtered(idx_fov_snr, 7);
% Scatter plot
if ~isempty(optimal_a_input)
scatter(optimal_a_input, optimal_a_interp, 50, colors(c_idx, :), ‘filled’);
% Fit and plot linear regression line if there is sufficient data
if length(optimal_a_input) > 1
model_a = fitlm(optimal_a_input, optimal_a_interp);
plot(model_a.Variables.x1, model_a.Fitted, ‘Color’, colors(c_idx, :), ‘LineWidth’, 2);
% Calculate additional performance metrics
r_squared_a = model_a.Rsquared.Ordinary;
rmse_a = calculate_rmse(optimal_a_input, optimal_a_interp);
mape_a = calculate_mape(optimal_a_input, optimal_a_interp);
mae_a = calculate_mae(optimal_a_input, optimal_a_interp);
made_a = calculate_made(optimal_a_input, optimal_a_interp);
% Store the performance metrics for this FOV and SNR value
performance_metrics(h).r_squared_a(fov_idx, snr_idx) = r_squared_a;
performance_metrics(h).rmse_a(fov_idx, snr_idx) = rmse_a;
performance_metrics(h).mape_a(fov_idx, snr_idx) = mape_a;
performance_metrics(h).mae_a(fov_idx, snr_idx) = mae_a;
performance_metrics(h).made_a(fov_idx, snr_idx) = made_a;
% Display text with performance metrics
text(mean(optimal_a_input), mean(optimal_a_interp), …
{[‘SNR = ‘, num2str(snr), ‘ dB’], …
[‘R^2 = ‘, num2str(r_squared_a)], …
[‘RMSE = ‘, num2str(rmse_a)], …
[‘MAPE = ‘, num2str(mape_a), ‘%’], …
[‘MAE = ‘, num2str(mae_a)], …
[‘MADE = ‘, num2str(made_a)]}, …
‘FontSize’, 10, ‘Color’, colors(c_idx, :));
end
end
c_idx = c_idx + 1;
end
end
xlabel(‘Optimal alpha_{e} (m^{-1})’);
ylabel(‘Optimal alpha_{e} interp (m^{-1})’);
title([‘Plot of optimal alpha_{e} vs optimal alpha_{e} interp for Height = ‘, num2str(h)]);
grid on;
hold off;
endText in the left corner and fitting line is missing from my fiures, please make correction to my code:
% Define heights, FOVs, and SNR values to test
heights = [1000, 2000, 3000, 4000];
fovs = [0.2, 0.5, 1, 2, 5, 10];
snr_values = [0, 25, 50, 75, 100];
% Function to calculate performance metrics
calculate_r_squared = @(x, y) 1 – sum((y – x).^2) / sum((y – mean(y)).^2);
calculate_rmse = @(x, y) sqrt(mean((y – x).^2));
calculate_mape = @(x, y) mean(abs((y – x) ./ y)) * 100;
calculate_mae = @(x, y) mean(abs(y – x));
calculate_made = @(x, y) mean(abs(y – mean(x)));
% Initialize arrays to store performance metrics
performance_metrics = struct();
% Loop over height values
for h = heights
% Filter the data for the current height
idx = (lookup_table(:, 1) == h);
data_filtered = lookup_table(idx, :);
% Initialize arrays to store performance metrics for each FOV and SNR value
performance_metrics(h).r_squared_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).rmse_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).mape_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).mae_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).made_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).r_squared_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).rmse_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).mape_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).mae_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).made_a = zeros(length(fovs), length(snr_values));
% Plot optimal_r_input vs. optimal_r_interp
figure;
hold on;
colors = jet(length(fovs) * length(snr_values));
c_idx = 1;
for fov_idx = 1:length(fovs)
for snr_idx = 1:length(snr_values)
fov = fovs(fov_idx);
snr = snr_values(snr_idx);
% Filter data for the current FOV and SNR
idx_fov_snr = (data_filtered(:, 2) == fov) & (data_filtered(:, 3) == snr);
optimal_r_input = data_filtered(idx_fov_snr, 4);
optimal_r_interp = data_filtered(idx_fov_snr, 5);
% Scatter plot
if ~isempty(optimal_r_input)
scatter(optimal_r_input, optimal_r_interp, 50, colors(c_idx, :), ‘filled’);
% Fit and plot linear regression line if there is sufficient data
if length(optimal_r_input) > 1
model_r = fitlm(optimal_r_input, optimal_r_interp);
plot(model_r.Variables.x1, model_r.Fitted, ‘Color’, colors(c_idx, :), ‘LineWidth’, 2);
% Calculate additional performance metrics
r_squared_r = model_r.Rsquared.Ordinary;
rmse_r = calculate_rmse(optimal_r_input, optimal_r_interp);
mape_r = calculate_mape(optimal_r_input, optimal_r_interp);
mae_r = calculate_mae(optimal_r_input, optimal_r_interp);
made_r = calculate_made(optimal_r_input, optimal_r_interp);
% Store the performance metrics for this FOV and SNR value
performance_metrics(h).r_squared_r(fov_idx, snr_idx) = r_squared_r;
performance_metrics(h).rmse_r(fov_idx, snr_idx) = rmse_r;
performance_metrics(h).mape_r(fov_idx, snr_idx) = mape_r;
performance_metrics(h).mae_r(fov_idx, snr_idx) = mae_r;
performance_metrics(h).made_r(fov_idx, snr_idx) = made_r;
% Display text with performance metrics
text(mean(optimal_r_input), mean(optimal_r_interp), …
{[‘SNR = ‘, num2str(snr), ‘ dB’], …
[‘R^2 = ‘, num2str(r_squared_r)], …
[‘RMSE = ‘, num2str(rmse_r)], …
[‘MAPE = ‘, num2str(mape_r), ‘%’], …
[‘MAE = ‘, num2str(mae_r)], …
[‘MADE = ‘, num2str(made_r)]}, …
‘FontSize’, 10, ‘Color’, colors(c_idx, :));
end
end
c_idx = c_idx + 1;
end
end
xlabel(‘Optimal R_{e} (mum)’);
ylabel(‘Optimal R_{e} interp (mum)’);
title([‘Plot of optimal R_{e} and optimal R_{e} interp for Height = ‘, num2str(h)]);
grid on;
hold off;
% Plot optimal_a_input vs. optimal_a_interp
figure;
hold on;
c_idx = 1;
for fov_idx = 1:length(fovs)
for snr_idx = 1:length(snr_values)
fov = fovs(fov_idx);
snr = snr_values(snr_idx);
% Filter data for the current FOV and SNR
idx_fov_snr = (data_filtered(:, 2) == fov) & (data_filtered(:, 3) == snr);
optimal_a_input = data_filtered(idx_fov_snr, 6);
optimal_a_interp = data_filtered(idx_fov_snr, 7);
% Scatter plot
if ~isempty(optimal_a_input)
scatter(optimal_a_input, optimal_a_interp, 50, colors(c_idx, :), ‘filled’);
% Fit and plot linear regression line if there is sufficient data
if length(optimal_a_input) > 1
model_a = fitlm(optimal_a_input, optimal_a_interp);
plot(model_a.Variables.x1, model_a.Fitted, ‘Color’, colors(c_idx, :), ‘LineWidth’, 2);
% Calculate additional performance metrics
r_squared_a = model_a.Rsquared.Ordinary;
rmse_a = calculate_rmse(optimal_a_input, optimal_a_interp);
mape_a = calculate_mape(optimal_a_input, optimal_a_interp);
mae_a = calculate_mae(optimal_a_input, optimal_a_interp);
made_a = calculate_made(optimal_a_input, optimal_a_interp);
% Store the performance metrics for this FOV and SNR value
performance_metrics(h).r_squared_a(fov_idx, snr_idx) = r_squared_a;
performance_metrics(h).rmse_a(fov_idx, snr_idx) = rmse_a;
performance_metrics(h).mape_a(fov_idx, snr_idx) = mape_a;
performance_metrics(h).mae_a(fov_idx, snr_idx) = mae_a;
performance_metrics(h).made_a(fov_idx, snr_idx) = made_a;
% Display text with performance metrics
text(mean(optimal_a_input), mean(optimal_a_interp), …
{[‘SNR = ‘, num2str(snr), ‘ dB’], …
[‘R^2 = ‘, num2str(r_squared_a)], …
[‘RMSE = ‘, num2str(rmse_a)], …
[‘MAPE = ‘, num2str(mape_a), ‘%’], …
[‘MAE = ‘, num2str(mae_a)], …
[‘MADE = ‘, num2str(made_a)]}, …
‘FontSize’, 10, ‘Color’, colors(c_idx, :));
end
end
c_idx = c_idx + 1;
end
end
xlabel(‘Optimal alpha_{e} (m^{-1})’);
ylabel(‘Optimal alpha_{e} interp (m^{-1})’);
title([‘Plot of optimal alpha_{e} vs optimal alpha_{e} interp for Height = ‘, num2str(h)]);
grid on;
hold off;
end Text in the left corner and fitting line is missing from my fiures, please make correction to my code:
% Define heights, FOVs, and SNR values to test
heights = [1000, 2000, 3000, 4000];
fovs = [0.2, 0.5, 1, 2, 5, 10];
snr_values = [0, 25, 50, 75, 100];
% Function to calculate performance metrics
calculate_r_squared = @(x, y) 1 – sum((y – x).^2) / sum((y – mean(y)).^2);
calculate_rmse = @(x, y) sqrt(mean((y – x).^2));
calculate_mape = @(x, y) mean(abs((y – x) ./ y)) * 100;
calculate_mae = @(x, y) mean(abs(y – x));
calculate_made = @(x, y) mean(abs(y – mean(x)));
% Initialize arrays to store performance metrics
performance_metrics = struct();
% Loop over height values
for h = heights
% Filter the data for the current height
idx = (lookup_table(:, 1) == h);
data_filtered = lookup_table(idx, :);
% Initialize arrays to store performance metrics for each FOV and SNR value
performance_metrics(h).r_squared_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).rmse_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).mape_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).mae_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).made_r = zeros(length(fovs), length(snr_values));
performance_metrics(h).r_squared_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).rmse_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).mape_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).mae_a = zeros(length(fovs), length(snr_values));
performance_metrics(h).made_a = zeros(length(fovs), length(snr_values));
% Plot optimal_r_input vs. optimal_r_interp
figure;
hold on;
colors = jet(length(fovs) * length(snr_values));
c_idx = 1;
for fov_idx = 1:length(fovs)
for snr_idx = 1:length(snr_values)
fov = fovs(fov_idx);
snr = snr_values(snr_idx);
% Filter data for the current FOV and SNR
idx_fov_snr = (data_filtered(:, 2) == fov) & (data_filtered(:, 3) == snr);
optimal_r_input = data_filtered(idx_fov_snr, 4);
optimal_r_interp = data_filtered(idx_fov_snr, 5);
% Scatter plot
if ~isempty(optimal_r_input)
scatter(optimal_r_input, optimal_r_interp, 50, colors(c_idx, :), ‘filled’);
% Fit and plot linear regression line if there is sufficient data
if length(optimal_r_input) > 1
model_r = fitlm(optimal_r_input, optimal_r_interp);
plot(model_r.Variables.x1, model_r.Fitted, ‘Color’, colors(c_idx, :), ‘LineWidth’, 2);
% Calculate additional performance metrics
r_squared_r = model_r.Rsquared.Ordinary;
rmse_r = calculate_rmse(optimal_r_input, optimal_r_interp);
mape_r = calculate_mape(optimal_r_input, optimal_r_interp);
mae_r = calculate_mae(optimal_r_input, optimal_r_interp);
made_r = calculate_made(optimal_r_input, optimal_r_interp);
% Store the performance metrics for this FOV and SNR value
performance_metrics(h).r_squared_r(fov_idx, snr_idx) = r_squared_r;
performance_metrics(h).rmse_r(fov_idx, snr_idx) = rmse_r;
performance_metrics(h).mape_r(fov_idx, snr_idx) = mape_r;
performance_metrics(h).mae_r(fov_idx, snr_idx) = mae_r;
performance_metrics(h).made_r(fov_idx, snr_idx) = made_r;
% Display text with performance metrics
text(mean(optimal_r_input), mean(optimal_r_interp), …
{[‘SNR = ‘, num2str(snr), ‘ dB’], …
[‘R^2 = ‘, num2str(r_squared_r)], …
[‘RMSE = ‘, num2str(rmse_r)], …
[‘MAPE = ‘, num2str(mape_r), ‘%’], …
[‘MAE = ‘, num2str(mae_r)], …
[‘MADE = ‘, num2str(made_r)]}, …
‘FontSize’, 10, ‘Color’, colors(c_idx, :));
end
end
c_idx = c_idx + 1;
end
end
xlabel(‘Optimal R_{e} (mum)’);
ylabel(‘Optimal R_{e} interp (mum)’);
title([‘Plot of optimal R_{e} and optimal R_{e} interp for Height = ‘, num2str(h)]);
grid on;
hold off;
% Plot optimal_a_input vs. optimal_a_interp
figure;
hold on;
c_idx = 1;
for fov_idx = 1:length(fovs)
for snr_idx = 1:length(snr_values)
fov = fovs(fov_idx);
snr = snr_values(snr_idx);
% Filter data for the current FOV and SNR
idx_fov_snr = (data_filtered(:, 2) == fov) & (data_filtered(:, 3) == snr);
optimal_a_input = data_filtered(idx_fov_snr, 6);
optimal_a_interp = data_filtered(idx_fov_snr, 7);
% Scatter plot
if ~isempty(optimal_a_input)
scatter(optimal_a_input, optimal_a_interp, 50, colors(c_idx, :), ‘filled’);
% Fit and plot linear regression line if there is sufficient data
if length(optimal_a_input) > 1
model_a = fitlm(optimal_a_input, optimal_a_interp);
plot(model_a.Variables.x1, model_a.Fitted, ‘Color’, colors(c_idx, :), ‘LineWidth’, 2);
% Calculate additional performance metrics
r_squared_a = model_a.Rsquared.Ordinary;
rmse_a = calculate_rmse(optimal_a_input, optimal_a_interp);
mape_a = calculate_mape(optimal_a_input, optimal_a_interp);
mae_a = calculate_mae(optimal_a_input, optimal_a_interp);
made_a = calculate_made(optimal_a_input, optimal_a_interp);
% Store the performance metrics for this FOV and SNR value
performance_metrics(h).r_squared_a(fov_idx, snr_idx) = r_squared_a;
performance_metrics(h).rmse_a(fov_idx, snr_idx) = rmse_a;
performance_metrics(h).mape_a(fov_idx, snr_idx) = mape_a;
performance_metrics(h).mae_a(fov_idx, snr_idx) = mae_a;
performance_metrics(h).made_a(fov_idx, snr_idx) = made_a;
% Display text with performance metrics
text(mean(optimal_a_input), mean(optimal_a_interp), …
{[‘SNR = ‘, num2str(snr), ‘ dB’], …
[‘R^2 = ‘, num2str(r_squared_a)], …
[‘RMSE = ‘, num2str(rmse_a)], …
[‘MAPE = ‘, num2str(mape_a), ‘%’], …
[‘MAE = ‘, num2str(mae_a)], …
[‘MADE = ‘, num2str(made_a)]}, …
‘FontSize’, 10, ‘Color’, colors(c_idx, :));
end
end
c_idx = c_idx + 1;
end
end
xlabel(‘Optimal alpha_{e} (m^{-1})’);
ylabel(‘Optimal alpha_{e} interp (m^{-1})’);
title([‘Plot of optimal alpha_{e} vs optimal alpha_{e} interp for Height = ‘, num2str(h)]);
grid on;
hold off;
end figure, text MATLAB Answers — New Questions
Implementing Transfer Function In Simulink.
Hi, I have a transfer function and have been struggling to implement it properly into simulink. ,,, and all change with respect to time and I want to be able to get . Furthermore, and depend on which I pass into a Matlab Block that calculates and respectively.
I tried using the Varying Transfer Fcn block, but I’d like to implement it using signals and blocks.
Thanks in advance, I’d really appreciate the help!Hi, I have a transfer function and have been struggling to implement it properly into simulink. ,,, and all change with respect to time and I want to be able to get . Furthermore, and depend on which I pass into a Matlab Block that calculates and respectively.
I tried using the Varying Transfer Fcn block, but I’d like to implement it using signals and blocks.
Thanks in advance, I’d really appreciate the help! Hi, I have a transfer function and have been struggling to implement it properly into simulink. ,,, and all change with respect to time and I want to be able to get . Furthermore, and depend on which I pass into a Matlab Block that calculates and respectively.
I tried using the Varying Transfer Fcn block, but I’d like to implement it using signals and blocks.
Thanks in advance, I’d really appreciate the help! transfer function, simulink MATLAB Answers — New Questions
signals matching between random modulations transmitter and humminbird sonar
hello i would like to ask how to match random signals of a transmitter to the signals of a humminbird imaging sonar so that the sonar is able to obtain imaging information from the random signals of the transmitter. is there a way of determining all the modulations of the sonar and the transmitter by scanning them. i will be using an sdr to send the random signals from the transmitter to the sonar. thanks very much.hello i would like to ask how to match random signals of a transmitter to the signals of a humminbird imaging sonar so that the sonar is able to obtain imaging information from the random signals of the transmitter. is there a way of determining all the modulations of the sonar and the transmitter by scanning them. i will be using an sdr to send the random signals from the transmitter to the sonar. thanks very much. hello i would like to ask how to match random signals of a transmitter to the signals of a humminbird imaging sonar so that the sonar is able to obtain imaging information from the random signals of the transmitter. is there a way of determining all the modulations of the sonar and the transmitter by scanning them. i will be using an sdr to send the random signals from the transmitter to the sonar. thanks very much. signals, match, transmitter, sonars MATLAB Answers — New Questions
Update bus selector by matlab script
Hi, is there a possibility to let a Bus Selector and Bus Creator update by a Matlab Script after I change the element name within a bus object?Hi, is there a possibility to let a Bus Selector and Bus Creator update by a Matlab Script after I change the element name within a bus object? Hi, is there a possibility to let a Bus Selector and Bus Creator update by a Matlab Script after I change the element name within a bus object? bus creator, bus selector, update MATLAB Answers — New Questions
plotting 2d graphs with decimals
I want to plot graph but gives me this error. this is the code i used
time_X_core224_6= readmatrix("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","A3:A4401")
time_X_core224_7= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","G3:G4401")
time_X_core224_9= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","M3:M4401")
time_X_core224_28= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","S3:S4401")
time_X_core224_38= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","Y3:Y4401")
time_X_core156421= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AE3:AE4401")
Core224_6_KY = readmatrix("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ4:BE4")
Core224_7_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ9:BE9")
Core224_9_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ14:BE14")
Core224_28_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ19:BE19")
Core224_38_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ24:BE24")
Core224_156421_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ29:BE29")
KY_Fig = plot(time_X_core224_6,Core224_6_KY)
Any solutions?I want to plot graph but gives me this error. this is the code i used
time_X_core224_6= readmatrix("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","A3:A4401")
time_X_core224_7= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","G3:G4401")
time_X_core224_9= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","M3:M4401")
time_X_core224_28= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","S3:S4401")
time_X_core224_38= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","Y3:Y4401")
time_X_core156421= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AE3:AE4401")
Core224_6_KY = readmatrix("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ4:BE4")
Core224_7_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ9:BE9")
Core224_9_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ14:BE14")
Core224_28_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ19:BE19")
Core224_38_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ24:BE24")
Core224_156421_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ29:BE29")
KY_Fig = plot(time_X_core224_6,Core224_6_KY)
Any solutions? I want to plot graph but gives me this error. this is the code i used
time_X_core224_6= readmatrix("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","A3:A4401")
time_X_core224_7= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","G3:G4401")
time_X_core224_9= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","M3:M4401")
time_X_core224_28= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","S3:S4401")
time_X_core224_38= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","Y3:Y4401")
time_X_core156421= readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AE3:AE4401")
Core224_6_KY = readmatrix("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ4:BE4")
Core224_7_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ9:BE9")
Core224_9_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ14:BE14")
Core224_28_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ19:BE19")
Core224_38_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ24:BE24")
Core224_156421_KY = readtable("Лист Microsoft Excel.xlsx","Sheet","Лист1","Range","AZ29:BE29")
KY_Fig = plot(time_X_core224_6,Core224_6_KY)
Any solutions? graph, plotting, 2d, error MATLAB Answers — New Questions
matlab command for delete bus objects
can any one help me, Matlab command for delete busobjects.can any one help me, Matlab command for delete busobjects. can any one help me, Matlab command for delete busobjects. busobjects MATLAB Answers — New Questions
Findings experimental values closest to the setpoint value
Hi there,
I will try to explain the issue I am having to the best of my ability (I have also attached an example excel for clarity). Essentially, in my experiment, I am trying to analyze the loads achieved at specific angles based on setpoint angles I am feeding the actuator (each case has different setpoints but in the case I am introducing here, the setpoints go from -50 to 10). There are two actuators in this example that I am testing (Compu1 and Compu2) (there are actually about 50 overall I’m testing but in this example, there are 2), each with a different achieved angle value and its equavlient load measurement. What I am trying to have Matlab do is export the load value of that actuator that best represents the neareast achieved angle based on the set point fed into it.
Reason for that, is that when I plot the loads achieved of the two actuators, my X axis (set point angle) will have ranging values for each individual actuator so I’m trying to essentially "normalize" the data based on my set "angles to plot" column in excel (increment of 0.1 degrees) and I would want matlab to just export the nearest value to that column so that each actuator can be properly plotted together against the same X range for direct comparsion.
I hope that made sense. Again, this example only includes 2 actutors but I would appreciate it if the solution can be tailored towards an X number of actuators.
Thanks so much in advance!Hi there,
I will try to explain the issue I am having to the best of my ability (I have also attached an example excel for clarity). Essentially, in my experiment, I am trying to analyze the loads achieved at specific angles based on setpoint angles I am feeding the actuator (each case has different setpoints but in the case I am introducing here, the setpoints go from -50 to 10). There are two actuators in this example that I am testing (Compu1 and Compu2) (there are actually about 50 overall I’m testing but in this example, there are 2), each with a different achieved angle value and its equavlient load measurement. What I am trying to have Matlab do is export the load value of that actuator that best represents the neareast achieved angle based on the set point fed into it.
Reason for that, is that when I plot the loads achieved of the two actuators, my X axis (set point angle) will have ranging values for each individual actuator so I’m trying to essentially "normalize" the data based on my set "angles to plot" column in excel (increment of 0.1 degrees) and I would want matlab to just export the nearest value to that column so that each actuator can be properly plotted together against the same X range for direct comparsion.
I hope that made sense. Again, this example only includes 2 actutors but I would appreciate it if the solution can be tailored towards an X number of actuators.
Thanks so much in advance! Hi there,
I will try to explain the issue I am having to the best of my ability (I have also attached an example excel for clarity). Essentially, in my experiment, I am trying to analyze the loads achieved at specific angles based on setpoint angles I am feeding the actuator (each case has different setpoints but in the case I am introducing here, the setpoints go from -50 to 10). There are two actuators in this example that I am testing (Compu1 and Compu2) (there are actually about 50 overall I’m testing but in this example, there are 2), each with a different achieved angle value and its equavlient load measurement. What I am trying to have Matlab do is export the load value of that actuator that best represents the neareast achieved angle based on the set point fed into it.
Reason for that, is that when I plot the loads achieved of the two actuators, my X axis (set point angle) will have ranging values for each individual actuator so I’m trying to essentially "normalize" the data based on my set "angles to plot" column in excel (increment of 0.1 degrees) and I would want matlab to just export the nearest value to that column so that each actuator can be properly plotted together against the same X range for direct comparsion.
I hope that made sense. Again, this example only includes 2 actutors but I would appreciate it if the solution can be tailored towards an X number of actuators.
Thanks so much in advance! matlab, optimization, plot MATLAB Answers — New Questions
I’m trying to plot matrix data from an Excel file, but the plot I obtained (named “2”) doesn’t match my expected result (named “1”); here’s my code—can anyone assist?
I am trying to plot my matrix data from an excel file. However, what I obtained is the same as what I desired. The expected plot is name 1, while what I have obtained is named 2. Here is my code:
% Load the matrix from the Excel sheet
matrix1 = readmatrix(‘Sample_Axes.xlsx’, ‘Sheet’, ‘one’);
% Create a figure with subplots
figure;
% Plot matrix1 using contour
subplot(1, 3, 1);
contourf(matrix1, 20, ‘LineColor’, ‘none’); % 20 contour levels, ‘LineColor’, ‘none’ for no contour lines
cb1 = colorbar;
colormap jet;
title(‘Matrix 1’);
Can someone help me out?I am trying to plot my matrix data from an excel file. However, what I obtained is the same as what I desired. The expected plot is name 1, while what I have obtained is named 2. Here is my code:
% Load the matrix from the Excel sheet
matrix1 = readmatrix(‘Sample_Axes.xlsx’, ‘Sheet’, ‘one’);
% Create a figure with subplots
figure;
% Plot matrix1 using contour
subplot(1, 3, 1);
contourf(matrix1, 20, ‘LineColor’, ‘none’); % 20 contour levels, ‘LineColor’, ‘none’ for no contour lines
cb1 = colorbar;
colormap jet;
title(‘Matrix 1’);
Can someone help me out? I am trying to plot my matrix data from an excel file. However, what I obtained is the same as what I desired. The expected plot is name 1, while what I have obtained is named 2. Here is my code:
% Load the matrix from the Excel sheet
matrix1 = readmatrix(‘Sample_Axes.xlsx’, ‘Sheet’, ‘one’);
% Create a figure with subplots
figure;
% Plot matrix1 using contour
subplot(1, 3, 1);
contourf(matrix1, 20, ‘LineColor’, ‘none’); % 20 contour levels, ‘LineColor’, ‘none’ for no contour lines
cb1 = colorbar;
colormap jet;
title(‘Matrix 1’);
Can someone help me out? matrix, importing excel data, contour MATLAB Answers — New Questions
Plotting a Simulink reinforcement learning environment
Hello there,
I have declared an environment starting from a simulink model:
env = rlSimulinkEnv("main","main/RL Agent",obsInfo,actInfo);
Then i have properly defined the training options and i have executed the training.
Now, I would like to plot the environment during the training process. In the help center i have found the possibility to use create a plot function exploiting a callback on environment update.
Are there any ways to do something similar also for the rlSimulinkEnv command without defining a custom environment with all the dynamic equations?
Thank you in advance.Hello there,
I have declared an environment starting from a simulink model:
env = rlSimulinkEnv("main","main/RL Agent",obsInfo,actInfo);
Then i have properly defined the training options and i have executed the training.
Now, I would like to plot the environment during the training process. In the help center i have found the possibility to use create a plot function exploiting a callback on environment update.
Are there any ways to do something similar also for the rlSimulinkEnv command without defining a custom environment with all the dynamic equations?
Thank you in advance. Hello there,
I have declared an environment starting from a simulink model:
env = rlSimulinkEnv("main","main/RL Agent",obsInfo,actInfo);
Then i have properly defined the training options and i have executed the training.
Now, I would like to plot the environment during the training process. In the help center i have found the possibility to use create a plot function exploiting a callback on environment update.
Are there any ways to do something similar also for the rlSimulinkEnv command without defining a custom environment with all the dynamic equations?
Thank you in advance. rl, simulink, enviroment, plot MATLAB Answers — New Questions
Issue on running PV array/VSC concurrently with Synchronous Machine
Hello,
I am having some trouble in simulating on Simulink this two blocks together:
PV array / Universal Bridge (VSC average model) – I don’t know which is responsible for the errors….
Synchronous Machine
I am able to run these blocks separately (by commenting one, then running the simulation and later commenting the other and running again) so I know it isn’t a problem with parameters and neither a singularity in the synchronous machine, which is one of the errors message that I receive when I try to simulate them together.
Also I know that, probably, it isn’t caused by the dynamics of the system because, as you can see in my model, I put a breaker on the PV array, and tried to run with it open, so that it doesn’t affect the dynamics of the system/synchronous machine, and even so the simulation goes wrong.
Does anybody knows what may be happening? Did this occur with you too? How can I solve it?
Please, try to run the cases I just said and see for yourself.*
The error happens at t = 0.0566 when both PV and SM are connected and non-commented.
*First, run "init_var.m" for setting the system parameters and variables.Hello,
I am having some trouble in simulating on Simulink this two blocks together:
PV array / Universal Bridge (VSC average model) – I don’t know which is responsible for the errors….
Synchronous Machine
I am able to run these blocks separately (by commenting one, then running the simulation and later commenting the other and running again) so I know it isn’t a problem with parameters and neither a singularity in the synchronous machine, which is one of the errors message that I receive when I try to simulate them together.
Also I know that, probably, it isn’t caused by the dynamics of the system because, as you can see in my model, I put a breaker on the PV array, and tried to run with it open, so that it doesn’t affect the dynamics of the system/synchronous machine, and even so the simulation goes wrong.
Does anybody knows what may be happening? Did this occur with you too? How can I solve it?
Please, try to run the cases I just said and see for yourself.*
The error happens at t = 0.0566 when both PV and SM are connected and non-commented.
*First, run "init_var.m" for setting the system parameters and variables. Hello,
I am having some trouble in simulating on Simulink this two blocks together:
PV array / Universal Bridge (VSC average model) – I don’t know which is responsible for the errors….
Synchronous Machine
I am able to run these blocks separately (by commenting one, then running the simulation and later commenting the other and running again) so I know it isn’t a problem with parameters and neither a singularity in the synchronous machine, which is one of the errors message that I receive when I try to simulate them together.
Also I know that, probably, it isn’t caused by the dynamics of the system because, as you can see in my model, I put a breaker on the PV array, and tried to run with it open, so that it doesn’t affect the dynamics of the system/synchronous machine, and even so the simulation goes wrong.
Does anybody knows what may be happening? Did this occur with you too? How can I solve it?
Please, try to run the cases I just said and see for yourself.*
The error happens at t = 0.0566 when both PV and SM are connected and non-commented.
*First, run "init_var.m" for setting the system parameters and variables. pv array, simulink, synchronous machine, universal bridge, vsc MATLAB Answers — New Questions
Gaussian spherical beam code
Does anyone know how to code a gaussian spherical beam in matlab?Does anyone know how to code a gaussian spherical beam in matlab? Does anyone know how to code a gaussian spherical beam in matlab? beams, structured beams, polarisation, propagation MATLAB Answers — New Questions
How do I submit my Kroger Feedback?
It’s my first visit at Kroger and I want to give my feedback to Kroger. I know little bit about Kroger feedback survey, but don’t have deep knowledge. Please guys if anyone know about this customer satisfaction Kroger customer satisfaction surveyIt’s my first visit at Kroger and I want to give my feedback to Kroger. I know little bit about Kroger feedback survey, but don’t have deep knowledge. Please guys if anyone know about this customer satisfaction Kroger customer satisfaction survey It’s my first visit at Kroger and I want to give my feedback to Kroger. I know little bit about Kroger feedback survey, but don’t have deep knowledge. Please guys if anyone know about this customer satisfaction Kroger customer satisfaction survey kroger feedback, feedback survey MATLAB Answers — New Questions
cell array to string array
fp31 =’#CC’ ‘#CB’ ‘#CN’ ‘#CO’ ‘#CP’ ‘#CF’ ‘#CS’ ‘#CI’ ‘#CQ’ ‘#CW’
i have a cell array like this ..
i want to convert every single cell of the array to string.
fp31(1)=’#CC’ should be string.fp31 =’#CC’ ‘#CB’ ‘#CN’ ‘#CO’ ‘#CP’ ‘#CF’ ‘#CS’ ‘#CI’ ‘#CQ’ ‘#CW’
i have a cell array like this ..
i want to convert every single cell of the array to string.
fp31(1)=’#CC’ should be string. fp31 =’#CC’ ‘#CB’ ‘#CN’ ‘#CO’ ‘#CP’ ‘#CF’ ‘#CS’ ‘#CI’ ‘#CQ’ ‘#CW’
i have a cell array like this ..
i want to convert every single cell of the array to string.
fp31(1)=’#CC’ should be string. strings, cell arrays MATLAB Answers — New Questions