How to store and then plot values in a for loop?
이전 댓글 표시
My goal: plot T1, T2, and T3 on a graph when the matrix is solved at each value of "i" from 0 to 50 for d. What my code currently does is solve a system at various values of "i" for three variables. the end result (aka the values I am trying to store) end up being T1, T2, and T3. The problem is, it only uses the last value of each of those, and not the entire spectrum of results. How can i store each result for those three values and plot them on a graph to show how they relate over time?
for d=0:.1:50;
i=d*-40000;
B=[-40000; i; 0];
A=[1 1 1; 10 28 40; 144 -240 180];
T=[(A^(-1)*B)];
T1=T(1);
T2=T(2);
T3=T(3);
end
답변 (1개)
Walter Roberson
2013년 2월 5일
A = [1 1 1; 10 28 40; 144 -240 180];
dvals = 0:.1:50;
for K = 1 : length(dvals)
d = dvals(K);
i = d * -40000;
B = [-40000; i; 0];
T = A \ B;
T1(K) = T(1);
T2(K) = T(2);
T3(K) = T(3);
end
plot( dvals, T1, '^', dvals, T2, 's', dvals, T3, 'p')
카테고리
도움말 센터 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!