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

1 次查看(过去 30 天)
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