Comapre matrix and function a operation
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hems
am 29 Aug. 2016
Kommentiert: Hems
am 31 Aug. 2016
A=[5 10 15 20 25] B=[1 1.5 2 4 8 14 17 25 18 16 22 23 17] the martix element B has to be compared with A to see between what range the fall and the lowest of the range has to be subtracted. for example 8 is between 5 and 10 it returns 8-5=3 25 is between 20 and 25 returns 25-20=5 Result:C=[1 1.5 2 4 3 4 2 5 3 1 2 3 2] tried with looping it is not fast enough. Kindly help me how to make it faster. Thanks!
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 29 Aug. 2016
Bearbeitet: Fangjun Jiang
am 29 Aug. 2016
Here is one solution. You might need to clarify some special cases. What the output should be if B contains value 25 or 20?
A=[5 10 15 20 25];
B=[1 1.5 2 4 8 14 17 25 18 16 22 23 17];
C=interp1(A,A,B,'linear')-interp1(A,A,B,'previous');
C(isnan(C))=B(isnan(C))
9 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MRI finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!