problem with condtitions in program
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello I have the following problem. I would like my program to subtract data from t1 from t. The purpose of my program is to assume that the values will be in a given range from 0.1900 to 0.2600. If the program subtracts the value of t1-t it receives a value in the given range then it is supposed to write this value into a variable. If, on the other hand, it does not receive a given value because, for example, there is a value of 68 the next one is only 88 and you can see that there is a lack of samples here. The program has to subtract more data from the vector until it receives the required value. The problem I have is that when I enter only one boundary value the program works, but when I want to enter a second one unfortunately the program does not work properly.
t=[0.0840000000000000,0.935000000000000,1.83900000000000,2.85400000000000,3.84500000000000,4.73200000000000,5.71000000000000,6.77900000000000,7.75000000000000,8.62400000000000,9.40900000000000,10.1720000000000,10.9430000000000,11.8060000000000,12.6770000000000,13.8250000000000,14.9320000000000,16.0030000000000,17.0310000000000,17.9190000000000,18.6890000000000,19.4270000000000,20.2120000000000,21.1040000000000,22.0370000000000,22.9860000000000,23.9090000000000,24.7900000000000,25.6760000000000,26.5840000000000,27.4870000000000,28.4060000000000,29.3130000000000,30.1520000000000,30.9750000000000,31.8760000000000,32.8330000000000,33.7180000000000,34.6020000000000,35.5970000000000,36.6070000000000,37.5170000000000,38.4710000000000,39.4750000000000,40.3770000000000,41.2570000000000,42.2520000000000,43.2800000000000,44.2160000000000,45.1490000000000,46.1790000000000,47.2260000000000,48.1870000000000,49.1360000000000,50.2220000000000,51.3240000000000,52.3400000000000,53.2800000000000,54.2750000000000,55.4050000000000,56.5300000000000,57.5530000000000,58.5850000000000,59.6640000000000,60.6640000000000,61.6140000000000,62.7610000000000,63.8230000000000,64.8040000000000,65.9080000000000,67.0560000000000,68.0810000000000,69.1380000000000,70.2060000000000,71.1900000000000,72.2370000000000,73.3250000000000,74.3050000000000,75.3310000000000,76.4380000000000,77.4460000000000,78.4250000000000,79.4900000000000,80.5880000000000,81.5760000000000,82.6540000000000,83.7080000000000,84.6390000000000,85.6360000000000,86.7050000000000,87.7210000000000,88.6310000000000,89.6890000000000,90.7540000000000,91.7460000000000,92.7570000000000,93.8380000000000,94.8490000000000,95.7690000000000,96.8210000000000]
t1=[0.196000000000000,1.13900000000000,2.03600000000000,3.04600000000000,4.04900000000000,4.93400000000000,5.90100000000000,6.97500000000000,7.95300000000000,8.83400000000000,9.61600000000000,10.3740000000000,11.1410000000000,12.0020000000000,12.8700000000000,14.0140000000000,15.1210000000000,16.1940000000000,17.2230000000000,18.1150000000000,18.8850000000000,19.6220000000000,20.4060000000000,21.2920000000000,22.2280000000000,23.1800000000000,24.1070000000000,24.9870000000000,25.8710000000000,26.7790000000000,27.6820000000000,28.6010000000000,29.5120000000000,30.3530000000000,31.1680000000000,32.0640000000000,33.0270000000000,33.9180000000000,34.7930000000000,35.7840000000000,36.8060000000000,37.7130000000000,38.6610000000000,39.6720000000000,40.5790000000000,41.4500000000000,42.4420000000000,43.4790000000000,44.4190000000000,45.3440000000000,46.3700000000000,47.4230000000000,48.3910000000000,49.3320000000000,50.4140000000000,51.5180000000000,52.5440000000000,53.4820000000000,54.4680000000000,55.5970000000000,56.7320000000000,57.7540000000000,58.7790000000000,59.8600000000000,60.8690000000000,61.8090000000000,62.9540000000000,64.0280000000000,65.0040000000000,66.1040000000000,67.2660000000000,68.3030000000000,NaN,NaN,88.0120000000000,88.9140000000000,89.9530000000000,91.0270000000000,92.0150000000000,93.0150000000000,94.0890000000000,95.1110000000000,96.0140000000000,97.0600000000000]
indexA = 1;
indexB =1;
for indexB = 1:length(t1)
c=t1(indexB)-t(indexA);
if (c<0.2600)&&(c<0.1900)
disp(t(indexA))
disp(t1(indexB))
d(indexB)=c;
disp('----------')
else
indexA=indexA+1;
c=t1(indexB)-t(indexA);
while (c>0.2600)&&(c>0.1900)
indexA=indexA+1;
c=t1(indexB)-t(indexA);
d(indexB)=c;
end
disp(t(indexA))
disp(t1(indexB))
d(indexB)=c;
disp('----------')
end
end
2 comentarios
Chandler Hall
el 15 de Nov. de 2022
What is the source of t and t1? They are different lengths. Would it not be more appropriate to ensure they are the same length and then check the value of t1(i) - t(i)? What is the ultimate purpose of d?
Respuestas (1)
David Hill
el 15 de Nov. de 2022
Editada: David Hill
el 15 de Nov. de 2022
Hard to understand what you are trying to do. Looks like you are good to about 72.
t=[0.0840000000000000,0.935000000000000,1.83900000000000,2.85400000000000,3.84500000000000,4.73200000000000,5.71000000000000,6.77900000000000,7.75000000000000,8.62400000000000,9.40900000000000,10.1720000000000,10.9430000000000,11.8060000000000,12.6770000000000,13.8250000000000,14.9320000000000,16.0030000000000,17.0310000000000,17.9190000000000,18.6890000000000,19.4270000000000,20.2120000000000,21.1040000000000,22.0370000000000,22.9860000000000,23.9090000000000,24.7900000000000,25.6760000000000,26.5840000000000,27.4870000000000,28.4060000000000,29.3130000000000,30.1520000000000,30.9750000000000,31.8760000000000,32.8330000000000,33.7180000000000,34.6020000000000,35.5970000000000,36.6070000000000,37.5170000000000,38.4710000000000,39.4750000000000,40.3770000000000,41.2570000000000,42.2520000000000,43.2800000000000,44.2160000000000,45.1490000000000,46.1790000000000,47.2260000000000,48.1870000000000,49.1360000000000,50.2220000000000,51.3240000000000,52.3400000000000,53.2800000000000,54.2750000000000,55.4050000000000,56.5300000000000,57.5530000000000,58.5850000000000,59.6640000000000,60.6640000000000,61.6140000000000,62.7610000000000,63.8230000000000,64.8040000000000,65.9080000000000,67.0560000000000,68.0810000000000,69.1380000000000,70.2060000000000,71.1900000000000,72.2370000000000,73.3250000000000,74.3050000000000,75.3310000000000,76.4380000000000,77.4460000000000,78.4250000000000,79.4900000000000,80.5880000000000,81.5760000000000,82.6540000000000,83.7080000000000,84.6390000000000,85.6360000000000,86.7050000000000,87.7210000000000,88.6310000000000,89.6890000000000,90.7540000000000,91.7460000000000,92.7570000000000,93.8380000000000,94.8490000000000,95.7690000000000,96.8210000000000];
t1=[0.196000000000000,1.13900000000000,2.03600000000000,3.04600000000000,4.04900000000000,4.93400000000000,5.90100000000000,6.97500000000000,7.95300000000000,8.83400000000000,9.61600000000000,10.3740000000000,11.1410000000000,12.0020000000000,12.8700000000000,14.0140000000000,15.1210000000000,16.1940000000000,17.2230000000000,18.1150000000000,18.8850000000000,19.6220000000000,20.4060000000000,21.2920000000000,22.2280000000000,23.1800000000000,24.1070000000000,24.9870000000000,25.8710000000000,26.7790000000000,27.6820000000000,28.6010000000000,29.5120000000000,30.3530000000000,31.1680000000000,32.0640000000000,33.0270000000000,33.9180000000000,34.7930000000000,35.7840000000000,36.8060000000000,37.7130000000000,38.6610000000000,39.6720000000000,40.5790000000000,41.4500000000000,42.4420000000000,43.4790000000000,44.4190000000000,45.3440000000000,46.3700000000000,47.4230000000000,48.3910000000000,49.3320000000000,50.4140000000000,51.5180000000000,52.5440000000000,53.4820000000000,54.4680000000000,55.5970000000000,56.7320000000000,57.7540000000000,58.7790000000000,59.8600000000000,60.8690000000000,61.8090000000000,62.9540000000000,64.0280000000000,65.0040000000000,66.1040000000000,67.2660000000000,68.3030000000000,NaN,NaN,88.0120000000000,88.9140000000000,89.9530000000000,91.0270000000000,92.0150000000000,93.0150000000000,94.0890000000000,95.1110000000000,96.0140000000000,97.0600000000000];
a=t1(1:72)-t(1:72)
b=a(a>=.19&a<=.26)%a few are not in the range, do not know what you want to do if they are not in the range
Ver también
Categorías
Más información sobre Logical 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!