How can I move through an array and a vector that need to be compared?

조회 수: 1 (최근 30일)
Andreea Juravschi
Andreea Juravschi 2019년 10월 29일
답변: Shubham Gupta 2019년 10월 29일
I have an Excel file that changed to an array after using the xlsread file, and ahve those values as well as a given vector of numebrs that I essentially need to compare using a euclidean distance formula. Basically the second, third ,and fourth columns are coordinates of airplanes and the vector given has the coordinates of a separate airplane. The coordinates of each are plugged into the formula and if the distance calculated is less than a given distance- the planes crash, and you print another cell array file of the same variation. i'm just not sure how to take the array of all the planes and their coordinates and move through them to plug in different values in the equation without hard coding?
  댓글 수: 1
Shubham Gupta
Shubham Gupta 2019년 10월 29일
Few questions:
"the vector given has the coordinates of a separate airplane" - what is the dimesion of the vector?
"you print another cell array file of the same variation" - cell array file, what do mean by that? and variation depends on which parameter?
"move through them to plug in different values in the equation" what do you mean by "move through" & which equation are you talking about?
Best way to explain the question is through some examples with necessary output. Cheers

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

답변 (1개)

Shubham Gupta
Shubham Gupta 2019년 10월 29일
My undersanding for the question.
For example you have a coordinates of 4 test planes (X) & coordinate for a separate reference plane (Y)
X = [1,2,3;
7,8,9;
4,5,6;
10,11,12];
Y = [1.4,1.5,1.6];
You first want to calculate distance of each plane in X with respect to (w.r.t.) Y, using
d = sqrt(sum(bsxfun(@minus,X,Y).^2,2)); % will produce column vector d of length = size(X,1),
% containing distance of coordinates in X wrt Y coordiante
Now, you want to put some kind of inequility to show with plane will crash, using a cell array?
d_limit = 7; % distance limit to predict whether plane will crash or not
JudgementCell = cell(size(d)); % prelocate cell array
JudgementCell(:,1) = {'No'}; % assign all cells as 'No' meaning plane won't crash
JudgementCell(d < d_limit) = {'Yes'}; % cells with d<d_limit will crash, so assign 'Yes'
Let me know if this is what you want or if you have any doubts.

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by