Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How to find find a number from a range of 2d array which is itself a range?

1 vue (au cours des 30 derniers jours)
yashvin
yashvin le 22 Juin 2015
Commenté : Stephen23 le 22 Juin 2015
Hi I have an array which is
Alt_greater_than_20000=[20960 27030 22800 29000]
I want to know if an element is found in a specific range of arrays. If yes, I pick up the middle value else i simply take the element as it is.
I generated my range of array as follows:
if true
num_fl=20;
array_fl=[];
initial_range=19950:50:20050;
% generate a range of flight level for i=1:num_fl
array_fl(i,:)=initial_range;
initial_range=initial_range+1000;
end
end
Its corresponding output is
array_fl =
19950 20000 20050
20950 21000 21050
21950 22000 22050
22950 23000 23050
23950 24000 24050
24950 25000 25050
25950 26000 26050
26950 27000 27050
27950 28000 28050
28950 29000 29050
29950 30000 30050
30950 31000 31050
31950 32000 32050
32950 33000 33050
33950 34000 34050
34950 35000 35050
35950 36000 36050
36950 37000 37050
37950 38000 38050
38950 39000 39050
So for example,
for 20960 i want its value to be 21000 for 27030 i want its value to be 27000 however for 22800, i want it to be 22800 itself (as it is not found in the range)
if true
FL=[];
%example Alt_greater_than_20000=[20960 27030 22800 29000] length_array=length(Alt_greater_than_20000);
% for i=1:length_array
for j=1:num_fl
for i=1:length_array
if Alt_greater_than_20000(i) >= array_fl(j,1) & Alt_greater_than_20000(i) <= array_fl(j,3)
FL(i)= array_fl(j,2);
else
FL(i)= Alt_greater_than_20000(i);
end
end
end
end
find attached my code. Can you please tell me where i went wrong. Am i using it correctly?
Yashvin

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by