How do you save variables to vectors and plot them?
이전 댓글 표시
This is my code:
valueOfP = [];
valueOfD = [];
valueOfT = [];
valueOfH = [];
Irrelevant code that functions on its own
end
fprintf(' Altitude is %d Temp = %d Pressure = %d Density = %d \n', h, t, p, d)
end
valueOfP(h) = p;
valueOfD(h) = d;
valueOfT(h) = t;
valueOfH(h) = h;
plot(valueOfP,valueOfH)
plot(valueOfT,valueOfH)
plot(valueOfD,valueOfH)
I keep getting error messages when I try to run the code. How would I go about saving the variables and then plotting pvs h, t vs h, and d vs h?
댓글 수: 3
madhan ravi
2019년 3월 14일
dipidi dapudi doo , totally vague
madhan ravi
2019년 3월 14일
post your code or upload your script file
Macy Walters
2019년 3월 14일
편집: madhan ravi
2019년 3월 14일
답변 (2개)
KSSV
2019년 3월 14일
x = zeros([],1) ;
y = zeros([],1) ;
for i = 1:10
x(i) = i ;
y(i) = rand ;
end
plot(x,y) ;
댓글 수: 2
Macy Walters
2019년 3월 14일
KSSV
2019년 3월 14일
You should specify the error.....how you expect us to correct it without code and showing us the error.
You define h to have values that are NOT positive integer:
for h=0:.5:105
which means that you cannot use h as an index. The simplest solution is to define a vector of h values, and loop over its indices. For your code you will need to do something like this:
hvec = 0:.5:105; % vector of h values
N = numel(hvec);
Pvec = nan(1,N); % preallocate output
Dvec = nan(1,N); % preallocate output
Tvec = nan(1,N); % preallocate output
for k = 1:N % loop over indices
h = hvec(k);
... your code
Pvec(k) = p;
Dvec(k) = d;
Tvec(k) = t;
end
plot(hvec,Pvec)
figure()
plot(hvec,Dvec)
figure()
plot(hvec,Tvec)
카테고리
도움말 센터 및 File Exchange에서 Sparse Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!