필터 지우기
필터 지우기

How to plot an array in negative axes

조회 수: 4 (최근 30일)
Anum Ahmed
Anum Ahmed 2018년 2월 3일
댓글: dpb 2018년 2월 4일
I have initialized an array using the following code:
xdim=6;
ydim=12;
V_new=zeros(xdim+1,ydim+1);
V_new(5,4:10)=15;
V_new
Now, I want to plot this array from x=-3:9 and y=0:6.
However, I am not sure how to plot the array at the negative x-axis.
  댓글 수: 3
dpb
dpb 2018년 2월 3일
Say what!? You have an array that is all zeros except for seven elements in the 5th row that are a constant.
What's to plot and what possible relation is there between the array and two totally unrelated variables
x =-3:9
y = 0:6
???
Anum Ahmed
Anum Ahmed 2018년 2월 3일
편집: dpb 2018년 2월 4일
Actually the complete code goes like this:
xdim=6;
ydim=12;
V=zeros(xdim+1,ydim+1);
V_new=zeros(xdim+1,ydim+1);
V_new(5,4:10)=15;
error=15;
iter=0;
while(error>0.0001)
iter=iter+1;
for i=2:1:xdim
for j=2:1:ydim
if V_new(i,j) == 15
continue
end
V_new(i,j)=(V_new(i-1,j)+V_new(i+1,j)+V_new(i,j-1)+V_new(i,j+1))/4;
end
end
error=max(max(abs(V_new-V)));
V=V_new;
end
figure('Name', 'Contours of Electric Potential');
contour(flipud(V),15,'ShowText','on')
grid on
It is used to determine the potential for a box. The plotted result are according to the array I initially defined. However, I want to plot the results from x=-3:9 and y=0:6.

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

채택된 답변

dpb
dpb 2018년 2월 4일
Ah...ok, now I see...presuming the array is assumed to match box boundaries, just define X,Y to match the dimensions you want--
X=linspace(-3,9,size(V,2));
Y=linspace(0,5,size(V,1));
contour(X,Y,flipud(V),15,'ShowText','on')
...
  댓글 수: 2
Anum Ahmed
Anum Ahmed 2018년 2월 4일
Greta, it works... Thanks a lot...!!!
dpb
dpb 2018년 2월 4일
No problem; I just "whiffed" on the question first go... :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by