how to ignore interp1 method if there is no data in extrated area.

1 visualización (últimos 30 días)
Hi
I am extracting 10 database from certain big area data and putting all 10 database in one graph for summing y values. For this I am using interp1 method to put all 10 database in one graph.
So my question is how I deal with interp1 when I have no data in extracted area. It says I need at least 2 point to use interp1 command. Is there any way to give command if my data points 0 or 1 just ignore it or something like this. The thing is I am picking random 10 areas to extract databases and every time I get different points in extracted areas.
% input data [NUMERIC,TXT,RAW]=XLSREAD('sihex.xlsx'); L=xlsread('damL.xlsx'); %%%%%% latitude a = 44; b = 47.5; r = (b-a).*rand(10,1) + a;
%%%%%%% longitude
c = 6.5; d = 7.5; k = (d-c).*rand(10,1) +c;
x=NUMERIC(:,5); y=NUMERIC(:,4); Mag=NUMERIC(:,9);
for iii=1:length(TXT); date_str(iii,:)=TXT(iii,2); end
date_num=datenum(date_str,'dd/mm/yyyy'); test_data11=datenum('01/01/1959','dd/mm/yyyy'); test_data12=datenum('01/01/1979','dd/mm/yyyy'); test_data21=datenum('01/01/1960','dd/mm/yyyy'); test_data22=datenum('01/01/1980','dd/mm/yyyy'); test_data31=datenum('01/01/1961','dd/mm/yyyy'); test_data32=datenum('01/01/1981','dd/mm/yyyy'); test_data41=datenum('01/01/1961','dd/mm/yyyy'); test_data42=datenum('01/01/1981','dd/mm/yyyy'); test_data51=datenum('01/01/1962','dd/mm/yyyy'); test_data52=datenum('01/01/1982','dd/mm/yyyy'); test_data61=datenum('01/01/1965','dd/mm/yyyy'); test_data62=datenum('01/01/1985','dd/mm/yyyy'); test_data71=datenum('01/01/1966','dd/mm/yyyy'); test_data72=datenum('01/01/1986','dd/mm/yyyy'); test_data81=datenum('01/01/1968','dd/mm/yyyy'); test_data82=datenum('01/01/1988','dd/mm/yyyy'); test_data91=datenum('01/01/1968','dd/mm/yyyy'); test_data92=datenum('01/01/1988','dd/mm/yyyy'); test_data101=datenum('01/01/1968','dd/mm/yyyy'); test_data102=datenum('01/01/1988','dd/mm/yyyy');
condition11=(Mag >= 2.5 & date_num > test_data11 & date_num < test_data12 & x > k(1,1)-L(1,1) & x < k(1,1)+L(1,1) & y > r(1,1)-L(1,1) & y < r(1,1)+L(1,1)); g11=ones(size(date_num(condition11)));
condition21=(Mag >= 2.5 & date_num > test_data21 & date_num < test_data22 & x > k(2,1)-L(2,1) & x < k(2,1)+L(2,1) & y > r(2,1)-L(2,1) & y < r(2,1)+L(2,1)); g21=ones(size(date_num(condition21)));
condition31=(Mag >= 2.5 & date_num > test_data31 & date_num < test_data32 & x > k(3,1)-L(3,1) & x < k(3,1)+L(3,1) & y > r(3,1)-L(3,1) & y < r(3,1)+L(3,1)); g31=ones(size(date_num(condition31)));
condition41=(Mag >= 2.5 & date_num > test_data41 & date_num < test_data42 & x > k(4,1)-L(4,1) & x < k(4,1)+L(4,1) & y > r(4,1)-L(4,1) & y < r(4,1)+L(4,1)); g41=ones(size(date_num(condition41)));
condition51=(Mag >= 2.5 & date_num > test_data51 & date_num < test_data52 & x > k(5,1)-L(5,1) & x <k(5,1)+L(5,1) & y > r(5,1)-L(5,1) & y < r(5,1)+L(5,1)); g51=ones(size(date_num(condition51)));
condition61=(Mag >= 2.5 & date_num > test_data61 & date_num < test_data62 & x > k(6,1)-L(6,1) & x < k(6,1)+L(6,1) & y > r(6,1)-L(6,1) & y < r(6,1)+L(6,1)); g61=ones(size(date_num(condition61)));
condition71=(Mag >= 2.5 & date_num > test_data71 & date_num < test_data72 & x > k(7,1)-L(7,1) & x < k(7,1)+L(7,1) & y > r(7,1)-L(7,1) & y < r(7,1)+L(7,1) ); g71=ones(size(date_num(condition71)));
condition81=(Mag >= 2.5 & date_num > test_data81 & date_num < test_data82 & x > k(8,1)-L(8,1) & x < k(8,1)+L(8,1) & y > r(8,1)-L(8,1) & y < r(8,1)+L(8,1)); g81=ones(size(date_num(condition81)));
condition91=(Mag >= 2.5 & date_num > test_data91 & date_num < test_data92 & x > k(9,1)-L(9,1) & x < k(9,1)+L(9,1) & y > r(9,1)-L(9,1) & y < r(9,1)+L(9,1)); g91=ones(size(date_num(condition91)));
condition101=(Mag >= 2.5 & date_num > test_data101 & date_num < test_data102 & x > k(10,1)-L(10,1) & x < k(10,1)+L(10,1) & y > r(10,1)-L(10,1) & y < r(10,1)+L(10,1)); g101=ones(size(date_num(condition101)));
all_times = unique([date_num11; date_num21; date_num31; date_num41;date_num51;date_num61;date_num71;date_num81;date_num91;date_num101;]); P11=date_num11; uniq = [true; diff(P11) ~= 0]; first_projected = interp1(P11(uniq), g11(uniq), all_times); P21=date_num21; uniq = [true; diff(P21) ~= 0]; second_projected = interp1(P21(uniq), g21(uniq), all_times); P31=date_num31; uniq = [true; diff(P31) ~= 0]; third_projected = interp1(P31(uniq), g31(uniq), all_times); P41=date_num41; uniq = [true; diff(P41) ~= 0]; forth_projected = interp1(P41(uniq), g41(uniq), all_times); P51=date_num51; uniq = [true; diff(P51) ~= 0]; fifth_projected = interp1(P51(uniq), g51(uniq), all_times); P61=date_num61; uniq = [true; diff(P61) ~= 0]; six_projected = interp1(P61(uniq), g61(uniq), all_times); P71=date_num71; uniq = [true; diff(P71) ~= 0]; seven_projected = interp1(P71(uniq), g71(uniq), all_times); P81=date_num81; uniq = [true; diff(P81) ~= 0]; eigth_projected = interp1(P81(uniq), g81(uniq), all_times); P91=date_num91; uniq = [true; diff(P91) ~= 0]; ninth_projected = interp1(P91(uniq), g91(uniq), all_times); P101=date_num101; uniq = [true; diff(P101) ~= 0]; ten_projected = interp1(P101(uniq), g101(uniq), all_times);
first_projected(isnan(first_projected)) = 0; second_projected(isnan(second_projected)) = 0; third_projected(isnan(third_projected)) = 0; forth_projected(isnan(forth_projected)) = 0; fifth_projected(isnan(fifth_projected)) = 0; six_projected(isnan(six_projected)) = 0; seven_projected(isnan(seven_projected))=0; eigth_projected(isnan(eigth_projected)) = 0; ninth_projected(isnan(ninth_projected)) = 0; ten_projected(isnan(ten_projected)) = 0;
data_total = first_projected + second_projected+third_projected+forth_projected+fifth_projected+six_projected+seven_projected+eight_projected+ninth_projected+ten_projected; figure; plot(all_times,data_total); hold on; Thanks!

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Feb. de 2016
You deal with it by looking at length() of your proposed input before the call and making a decision about what you want the result to be if you have 0 or 1 points. This is not something that interp1() can handle for you.
  1 comentario
davit petraasya
davit petraasya el 5 de Feb. de 2016
Hi Walter. Thanks for you concern again!!! Is there any other function to deal with the problem instead of interp1()? Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Bar Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by