Assigning matrix rows to the same value and plotting

Hi! So I'm relatively new to coding, so I'm sure there is a simple answer for this. Anyways, here is my problem:
I have a matrix, say x = [1 2 3;4 5 6;7 8 9], and each row corresponds to a different value, say u = -3,0,3. I'm trying to generate a plot like (-3, [1 2 3]), (0,[4 5 6]), (3, [7 8 9]). But I'm having some trouble.
My idea was to generate a matrix of two columns using the following code:
plot_data = [];
for i=1:length(u)
for m = 1:length(x)
x1 = u(i)
y1 = x(i,m)
plot_data(m ,1) = x1
plot_data(m ,2) = y1
end
end
I'm sure I'm doing this in a very roundabout way, and the code I wrote doesn't work correctly. Can anyone give me some help?

댓글 수: 1

I don't know what "a plot like (-3, [1 2 3]), (0,[4 5 6]), (3, [7 8 9])" looks like. Mock up something in Photoshop, or draw something and take a photo or it or scan it in, and post a picture of it.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2017년 2월 17일
x = [1 2 3;4 5 6;7 8 9];
u = [-3,0,3];
y = repmat(u(:), 1, size(x,2));
plot(x.', y.')
ylim([min(u)-1, max(u)+1])

추가 답변 (0개)

카테고리

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

질문:

2017년 2월 17일

댓글:

2017년 2월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by