plotting selected lines from a matrix
10 次查看(过去 30 天)
显示 更早的评论
Hello! This was from a response last week from Sean de for plotting 9 2-D lines for a 3x3x4 matrix:
test = repmat(magic(3),[1 1 4]); %each vector into the third dimension will be the same (so we can verify accuracy)
test2 = reshape(permute(test,[3 2 1]),size(test,3),[]); %permute it and reshape it so that each column represents one vector into the third dimension
plot(test2) %plot it
I've been fiddling around with this code and was wondering: is there a way to print the data from each row on a separate graphs? So for this matrix have the output 3 charts with three lines each.
1 个评论
Matt Fig
2011-6-21
I don't see how you can get 3 charts with separate lines each (9 plots total) by plotting the rows of a 4-by-9 matrix (test2). Did you mean to plot the columns instead?
回答(2 个)
Sean de Wolski
2011-6-21
doc subplot
Then use a FOR-loop to navigate through.
figure;
for ii = 1:3
subplot(3,1,ii)
hold on
plot(matrix((3*(ii-1)+1):(3*ii),:).')
end
EDIT per comments:
for ii = 1:3
figure
plot(matrix((3*(ii-1)+1):(3*ii),:)')
end
Doesn't produce three unique figures with three lines each?
6 个评论
Walter Roberson
2011-6-21
for ii = 1:3
fig = figure;
axh = gca('Parent',fig);
plot(axh, matrix((3*(ii-1)+1):(3*ii),:).')
end
Matt Fig
2011-6-21
I still think you meant to plot the columns, not the rows. But this works for me:
test = repmat(magic(3),[1 1 4]);
test2 = reshape(permute(test,[3 2 1]),size(test,3),[]);
for ii = [0 3 6]
figure
plot(test2(:,(1:3)+ii))
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!