필터 지우기
필터 지우기

plot within a for loop and if statment

조회 수: 1 (최근 30일)
Kole
Kole 2014년 11월 10일
댓글: Kole 2014년 11월 10일
i have this data of wells, where in the first column i need to sort out all the 1's in that coulmn and plot the x,y,z corresponding to that row where the 1 is. this is the code i have
b=sum(a==1);
hold on
for n=1:221
if a(n)==1
;
plot3(xTop(n),yTop(n),1:b:0'k-')
n=n+1;
end
end
the coulmn is 221 rows long and i have the vaiables for the x and y shown but the z needs to go from 1 to 0 and i cant get the legth right or something?? if this is confusing ask me more questions thank you

채택된 답변

Image Analyst
Image Analyst 2014년 11월 10일
No for loop is needed.
% Find rows of "a" with 1's in the first column of "a".
rowsWith1s = a(:,1) == 1;
% Now extract them from the other arrays.
% (optional - you could do this inside plot3() if you want).
x = xTop(rowsWith1s);
y = yTop(rowsWith1s);
z = zTop(rowsWith1s);
% Now plot
plot3(x, y, z, 'bo-', 'LineWidth', 3);
% Make it fancy.
grid on;
xlabel('xTop', 'FontSize', 25);
ylabel('yTop', 'FontSize', 25);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
  댓글 수: 4
Kole
Kole 2014년 11월 10일
This is What i have now but still wont work
b=sum(a==1)
Nodev=(a(:,1)==1);
plot3(xTop(Nodev),yTop(Nodev),1:b:0,'k-')
doesnt need to fancy or anything but i just need the vectors to be the same length
Kole
Kole 2014년 11월 10일
xTopand yTop are my x and y values and a is the first column with the ones and twos in it. but then i need my z values to go from 1 to 0. so the vector must be the same length as xTop(Nodev)

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by