How to make multiple graphs in one plot with a for loop?
Hello, I want multiple graphs in one plot. So different dfranges plotted to see the T2. But we only get one df = -500 or df=500 all the time. What do we do wrong??
close all;
clear;
clc;
% Initial values and parameters
T2 = 0.052; % Needs to be changed > T1 needs to be checked in T2prep_function
M0 = 1;
TErange = 0.005:0.01:0.1;
T2range = 0.040:0.002:0.064; % Needs to be changed
dfrange = 100; % Scalar value for frequency range
B1var = 1; % 1 means no change in flip angle
Nspins = 500;
MLEV_size = 4; % Can be 4, 8, and 16
Mzprep = zeros(size(TErange));
compound = ‘yes’; % ‘yes’ for compound MLEV, ‘no’ for simple MLEV
%% Comparing off resonances
df_range = -500:100:500; % Range of off-resonance values
% Create figure
figure(3);
hold on;
% Initialize legend cell array
legendstrings = cell(size(df_range));
% Loop over df_range and plot each line
for n = 1:length(df_range)
fprintf(‘Processing df = %dn’, df_range(n));
% Calculate T2fit for the current df_range value
T2fit = calculate_multi_T2(T2range, TErange, MLEV_size, Nspins, df_range(n), M0, B1var, compound);
% Print T2fit for debugging purposes
fprintf(‘T2fit for df = %d: %sn’, df_range(n), mat2str(T2fit));
% Plot T2fit with a DisplayName that corresponds to the current df_range value
plot(T2range, T2fit, ‘DisplayName’, sprintf(‘df = %d’, df_range(n)));
% Store legend entry for current df_range value
legendstrings{n} = sprintf(‘df = %d’, df_range(n));
end
% Finish the plot
hold off;
disp(‘Simulation finished’);
% Add labels, legend, title, and grid
xlabel(‘Initial T2 (s)’);
ylabel(‘Fitted T2 (s)’);
legend(legendstrings, ‘Location’, ‘northwest’);
title(‘Different off-resonance values’);
grid on;Hello, I want multiple graphs in one plot. So different dfranges plotted to see the T2. But we only get one df = -500 or df=500 all the time. What do we do wrong??
close all;
clear;
clc;
% Initial values and parameters
T2 = 0.052; % Needs to be changed > T1 needs to be checked in T2prep_function
M0 = 1;
TErange = 0.005:0.01:0.1;
T2range = 0.040:0.002:0.064; % Needs to be changed
dfrange = 100; % Scalar value for frequency range
B1var = 1; % 1 means no change in flip angle
Nspins = 500;
MLEV_size = 4; % Can be 4, 8, and 16
Mzprep = zeros(size(TErange));
compound = ‘yes’; % ‘yes’ for compound MLEV, ‘no’ for simple MLEV
%% Comparing off resonances
df_range = -500:100:500; % Range of off-resonance values
% Create figure
figure(3);
hold on;
% Initialize legend cell array
legendstrings = cell(size(df_range));
% Loop over df_range and plot each line
for n = 1:length(df_range)
fprintf(‘Processing df = %dn’, df_range(n));
% Calculate T2fit for the current df_range value
T2fit = calculate_multi_T2(T2range, TErange, MLEV_size, Nspins, df_range(n), M0, B1var, compound);
% Print T2fit for debugging purposes
fprintf(‘T2fit for df = %d: %sn’, df_range(n), mat2str(T2fit));
% Plot T2fit with a DisplayName that corresponds to the current df_range value
plot(T2range, T2fit, ‘DisplayName’, sprintf(‘df = %d’, df_range(n)));
% Store legend entry for current df_range value
legendstrings{n} = sprintf(‘df = %d’, df_range(n));
end
% Finish the plot
hold off;
disp(‘Simulation finished’);
% Add labels, legend, title, and grid
xlabel(‘Initial T2 (s)’);
ylabel(‘Fitted T2 (s)’);
legend(legendstrings, ‘Location’, ‘northwest’);
title(‘Different off-resonance values’);
grid on; Hello, I want multiple graphs in one plot. So different dfranges plotted to see the T2. But we only get one df = -500 or df=500 all the time. What do we do wrong??
close all;
clear;
clc;
% Initial values and parameters
T2 = 0.052; % Needs to be changed > T1 needs to be checked in T2prep_function
M0 = 1;
TErange = 0.005:0.01:0.1;
T2range = 0.040:0.002:0.064; % Needs to be changed
dfrange = 100; % Scalar value for frequency range
B1var = 1; % 1 means no change in flip angle
Nspins = 500;
MLEV_size = 4; % Can be 4, 8, and 16
Mzprep = zeros(size(TErange));
compound = ‘yes’; % ‘yes’ for compound MLEV, ‘no’ for simple MLEV
%% Comparing off resonances
df_range = -500:100:500; % Range of off-resonance values
% Create figure
figure(3);
hold on;
% Initialize legend cell array
legendstrings = cell(size(df_range));
% Loop over df_range and plot each line
for n = 1:length(df_range)
fprintf(‘Processing df = %dn’, df_range(n));
% Calculate T2fit for the current df_range value
T2fit = calculate_multi_T2(T2range, TErange, MLEV_size, Nspins, df_range(n), M0, B1var, compound);
% Print T2fit for debugging purposes
fprintf(‘T2fit for df = %d: %sn’, df_range(n), mat2str(T2fit));
% Plot T2fit with a DisplayName that corresponds to the current df_range value
plot(T2range, T2fit, ‘DisplayName’, sprintf(‘df = %d’, df_range(n)));
% Store legend entry for current df_range value
legendstrings{n} = sprintf(‘df = %d’, df_range(n));
end
% Finish the plot
hold off;
disp(‘Simulation finished’);
% Add labels, legend, title, and grid
xlabel(‘Initial T2 (s)’);
ylabel(‘Fitted T2 (s)’);
legend(legendstrings, ‘Location’, ‘northwest’);
title(‘Different off-resonance values’);
grid on; for loop multiple graphs in one plot MATLAB Answers — New Questions