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