Stem plot inside a for loop
Afficher commentaires plus anciens
Hi,
I have a structure (attached) with the data arranged as follows:
for k=1:n
structure.stormk.data
where data refers to 10 different doubles.
I need a stem plot with the format attached (picture). The x-axis will cover k=1:n storms, and the data is plotted for each of them as shown.
At the end I will end up with 10 of these plots (data), covering the k storms.
Can I get some help with this type of plot? Thanks

Réponse acceptée
Plus de réponses (1)
TADA
le 25 Jan 2019
I didn't use your data because I have no idea what you want from it
if exist('fig1', 'var') && ishandle(fig1)
close(fig1);
end
fig1 = figure(1);
k = 10;
n = randi(4, 1, k) + 2; % random mock n data points per storm
intervalBetweenStorms = 20;
for i = 1:k
x = (1:n(i)) + i*intervalBetweenStorms;
y = normrnd(10, 2, 1, n(i));
stem(x, y, 'b', 'Marker', 'none');
hold on;
end
xticks((1:k)*intervalBetweenStorms);
xticklabels(strcat('Storm ', cellfun(@num2str, num2cell(1:k), 'UniformOutput', false)));
Catégories
En savoir plus sur Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!