MATLAB Answers

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

3 views (last 30 days)
Andreea Juravschi
Andreea Juravschi on 29 Oct 2019
Answered: Shubham Gupta on 29 Oct 2019
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 Comment

Shubham Gupta
Shubham Gupta on 29 Oct 2019
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

Sign in to comment.

Answers (1)

Shubham Gupta
Shubham Gupta on 29 Oct 2019
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.

  0 Comments

Sign in to comment.

Products


Release

R2019a