필터 지우기
필터 지우기

Appending a row vector into a matrix based on given conditions

조회 수: 1 (최근 30일)
Michael Wu
Michael Wu 2020년 2월 20일
댓글: Michael Wu 2020년 2월 20일
In my current code I have created a 604x1 matrix called b where I subtracted -60 and -550, the smaller of the values would then call a row in a larger matrix, 604x3, called data and append the row into one of the two empty matrices I have set up plane550 and plane60 depending on whichever value was greater than the other. Could someone guide me as to how to fix the problem in my code given below as running it gives me a single matrix that is equal to data in size.
xzplane60 = [];
xzplane550 = [];
for ii = 1:size(equakemat,1)
if abs(b(ii)-60) > abs(b(ii)-550)
xzplane550 = [xzplane550; equakemat(ii,:)];
else
xzplane60 = [xzplane60; equakemat(ii,:)];
end
end

채택된 답변

James Tursa
James Tursa 2020년 2월 20일
편집: James Tursa 2020년 2월 20일
x = abs(b-60) > abs(b-550); % fixed typo
xzplane550 = equakemat(x,:);
xzplane60 = equakemat(~x,:);
If all the data ends up in only one matrix, then all the data is closer to one of the comparison values.
  댓글 수: 5
James Tursa
James Tursa 2020년 2월 20일
Examine your b vector closely. What exactly is in it? Pause the code in the debugger and take a look at it to make sure it is what you think it is.
Michael Wu
Michael Wu 2020년 2월 20일
ohhhh i see i used the wrong vector i had another one labelled c that gave the correct output sorry for the inconvienience.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by