plotting selected lines from a matrix

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
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
Sean de Wolski 2011년 6월 21일

1 개 추천

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

Donald
Donald 2011년 6월 21일
hey, the subplot works well but is there a way to have to produce 3 different windows?
Sean de Wolski
Sean de Wolski 2011년 6월 21일
Three different figures instead of subplots?
Sure:
for ii = 1:3
figure;
plot(what I have above)
end
Donald
Donald 2011년 6월 21일
hmm, that doesn't seem to work for me. It simply outputs two blank figures and one that plots the 1-9 rather than all 1s,2s,3s,...
Sean de Wolski
Sean de Wolski 2011년 6월 21일
see edit.
Donald
Donald 2011년 6월 21일
Still no luck. I'm adding this code to what I had above, deleting the original "plot(test2)" and replacing "matrix" with "test2". The code seems to be only plotting the first magic square rather than plotting through the 3rd dimension.
Walter Roberson
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
Matt Fig 2011년 6월 21일

1 개 추천

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

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2011년 6월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by