compare Element of 2 arrays different size
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everyone,
I have come across a few issues whilst working on my project. I would greatly appreciate any help
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/155177/image.png)
In Workspace 3 arrays are given : "Section_v "with 22 Elements, Covered Road 412 Elements and Speedlimits 23 Elements. Each element of Section_V corresponds to a value of Speedlimits
For example: For 12.3496 meter there is a Speedlimit of 20 km/h (see attached)
Now to get into the crux of the issue.
I would like to create an m-file that compares the first element of Section_v with the first element of Covered Road and if it is found to be greater, it will go to next element of Covered Road. This will go on untill this condition does not apply and thus the value off "speedlimits" will be written in all cells by the new Array Speed column where this condition is correct.
At the next Step the first value of "section_v" will add up to the second one and the process will continue
Example:
1) 12,3496 >= 12,3496 --> Speed = 20 (first element off the Speed array)
12,3496 >= 24,85227 this not true, therefore we have to take the value of the next element of Section_V|_|
2) 12,3496 +236,5407 >= 24,85227707 --->> Speed = 50 (second element off the Speed array )
12,3496 +236,5407 >= 38,9555219 --->> Speed = 50 ( third element off the Speed array )
12,3496 +236,5407 >= 300 this not true, therefore we have to take the value of the next element of Section_V
3) 12,3496 +236,5407 +623,4659857 >= 300 -----> Speed = 30 ( fourth element off the Speed array )
..ect
One of the difficulties with this is that " Section_V " vectors are not the same length as those in "Covered Road ". Therefore , I thought that if n = 24 the value of the rest from element of "speed" would be 130.
Once again I would appreciate any help that is available.
Many thanks
JayJay
3 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!