Stem plot inside a for loop
显示 更早的评论
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

采纳的回答
更多回答(1 个)
TADA
2019-1-25
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)));
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!