Plotting a function with polyfit and a for loop

조회 수: 4 (최근 30일)
Ryan
Ryan 2013년 3월 5일
I need to use polyfit and a for loop to create a plot in Matlab. However, here's the catch: The values that need to be graphed need to be taken out from an inputted matrix. For example: the matrix is: [1 2 3; 4 5 6; 7 8 9; 10 11 12]. But I only need to graph the first two rows as such: the first row are the x values and the second row are the y values. And then create another graph with the third row being the x values, and the fourth row being the y values. But this also has to work for an unlimited number of inputs or rows. Any help is appreciated!

채택된 답변

the cyclist
the cyclist 2013년 3월 5일
Here is one way
M = [1 2 3; 4 5 6; 7 8 9; 10 11 12];
nrows = size(M,1);
for nr = 1:2:nrows
figure
x = M(nr, :);
y = M(nr+1,:);
plot(x,y)
end
  댓글 수: 2
Ryan
Ryan 2013년 3월 5일
Thanks! Worked great. All i had to add was a polyfit function and then plot that.
the cyclist
the cyclist 2013년 3월 5일
Please "accept" this answer, which may help people seeking similar answers in the future.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by