I wrote this code using Matlab R2014a in order to loop through a virtual grid:
clear, clc
format long g
load rN_Tang.txt
load aN_Tang.txt
c=aN_Tang(:,:);
f=rN_Tang(:,:);
DepthsA=-c(:,3);
LongitudeA=c(:,1);
DepthsR=-f(:,3);
LongitudeR=f(:,1);
for I=724:747;
J=2:8;
k=1:length(aN_Tang);
l=1:length(rN_Tang);
if ((I<LongitudeA(k)<=I+1 & J<DepthsA(k)<=J+1) & ...
(I<LongitudeR(l)<=I+1 & J<DepthsR(l)<=J+1))
if (isempty(DepthsA(k))==0 & isempty(DepthsR(l))==1)
Zmoy(I,J)=min(DepthsA(k));
elseif (isempty(DepthsA(k))==1 & isempty(DepthsR(l))==0)
Zmoy(I,J)=min(DepthsR(l));
elseif (isempty(DepthsA(k))==1 & isempty(DepthsR(l))==1)
%Ne rien faire, i.e "Void"
elseif (isempty(DepthsA(k))==0 & isempty(DepthsR(l))==0)
zAmin(I,J)=min(DepthsA(k));
DZ(I,J)=min(abs(zAmin(I,J)-DepthsR(l)));
if zAmin(I,J)<=DepthsR(l)
zRmin(I,J)=zAmin(I,J)+DZ(I,J);
else
zRmin(I,J)=zAmin(I,J)-DZ(I,J);
end
Zmoy(I,J)=(zAmin(I,J)+zRmin(I,J))/2;
end
end
Zm=-1*mean(Zmoy(I,J))
end
Matlab response :"
Error using < Matrix dimensions must agree.
Error in plN_Tang (line 60)
if ((I<LongitudeA(k)<=I+1 & J<DepthsA(k)<=J+1) & (I<LongitudeR(l)<=I+1 & J<DepthsR(l)<=J+1))"
What's wrong with the loop?
PS:I'd be so grateful if someone has an idea about this issue!

 채택된 답변

dpb
dpb 2015년 3월 16일
편집: dpb 2015년 3월 22일

0 개 추천

...
for I=724:747;
J=2:8;
k=1:length(aN_Tang);
l=1:length(rN_Tang);
if ((I<LongitudeA(k)<=I+1 & J<DepthsA(k)<=J+1) & ...
(I<LongitudeR(l)<=I+1 & J<DepthsR(l)<=J+1))
...
J, k, and l are invariant and so should be outside the loop...
J=2:8;
k=1:length(aN_Tang);
l=1:length(rN_Tang);
for I=724:747;
if ((I<LongitudeA(k)<=I+1 & J<DepthsA(k)<=J+1) & ...
(I<LongitudeR(l)<=I+1 & J<DepthsR(l)<=J+1))
...
Now I is a single value and while k is a vector of some unknown length but thus the returned subarray LongitudeA(k) is also of that length (presuming the size of the array is commensurate with that and the values are within the array bounds). But, you have a disparate size between a single value I and a vector LongitudeA(k) which causes a Matlab failure. Similar problems occur with the other arrays.
Not precisely sure what you're really after here so not positive the right coding solution...

댓글 수: 2

Marouane  Berrada
Marouane Berrada 2015년 3월 22일
Hi, What I want is to find the lesser value of the Vector "DepthsA" through a grid of 0.2x0.2.
Anyway, thank you very much for responding
dpb
dpb 2015년 3월 22일
I don't know what that means, precisely, what's wrong with
min(DepthsA)
??

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 3월 16일

댓글:

dpb
2015년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by