Hi Andrew,
I understand that you want to display legends for unknown number of plots with dynamically changing data. You can use “legend” function in MATLAB along with cell arrays to store the legend names. Please refer to the below example to achieve this.
% Example data for velocities and corresponding heights
velocities = [36, 42, 48, 54]; % Example velocities
heights = [10, 15, 20, 25]; % Example heights
% Create an empty cell array to store legend names
legendNames = cell(1, numel(velocities));
% Plot the data and store legend names
hold on
for i = 1:numel(velocities)
% Generate data for each velocity (example calculation)
x = linspace(0, 10, 100);
y = heights(i) * sin(velocities(i) * x);
% Plot the data
plot(x, y);
% Store the legend name
legendNames{i} = num2str(velocities(i));
end
hold off
% Display the legend
legend(legendNames, 'Location', 'best');
You can dynamically update the "velocities" and "heights" arrays based on user input.
Hope this helps!