[Scilab-users] ugly code improvement (with vectorization)
Carrico, Paul
paul.carrico at esterline.com
Tue Jun 27 09:05:40 CEST 2017
Dear All,
Can I ask advice to correct this ugly/slow code (using vectorization)?
In the example here bellow, I want
- to capture the non-null values of each line from the 5th column - each row can have different "length"
- the 4th column indicates how many values there're i.e the length
- Then to put this values in a vector previously initialized
If I can extract the values with ''Elements(k,[5: Elements (k,4)]'', I do not know how to put it the ''View'' matrix without using dynamic allocation ([View ; Elements (k,4) ... indeed I'm using block and not explicit index
Thanks for your time
Paul
########################################################
View = zeros(dim,2); // dim previously calculated
n = 1;
for k = 1 : size(Elements,1)
for m = 1 : Elements (k,4)
View(n,1) = Elements (k,4+m);
n = n+1;
end
end
with
Elements = [
1. 1. 29. 8. 81. 82. 83. 124. 165. 164. 163. 122. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
2. 1. 29. 8. 83. 84. 85. 126. 167. 166. 165. 124. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
3. 1. 29. 8. 85. 86. 87. 128. 169. 168. 167. 126. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
4. 1. 29. 8. 87. 88. 89. 130. 171. 170. 169. 128. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
5. 1. 29. 8. 89. 90. 91. 132. 173. 172. 171. 130. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
....
797. 1. 8. 20. 2193. 2194. 2195. 2219. 2257. 2256. 2255. 2218. 3515. 3516. 3517. 3541. 3579. 3578. 3577. 3540. 2854. 2856. 2918. 2916.
798. 1. 8. 20. 2195. 2196. 2197. 2220. 2259. 2258. 2257. 2219. 3517. 3518. 3519. 3542. 3581. 3580. 3579. 3541. 2856. 2858. 2920. 2918.
799. 1. 8. 20. 2197. 2198. 2199. 2221. 2261. 2260. 2259. 2220. 3519. 3520. 3521. 3543. 3583. 3582. 3581. 3542. 2858. 2860. 2922. 2920.
800. 1. 8. 20. 2199. 2200. 2201. 2222. 2263. 2262. 2261. 2221. 3521. 3522. 3523. 3544. 3585. 3584. 3583. 3543. 2860. 2862. 2924. 2922.
...
1047. 999. 3. 2. 3587. 3582. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
1048. 999. 3. 2. 3587. 3583. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
1049. 999. 3. 2. 3587. 3584. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
1050. 999. 3. 2. 3587. 3585. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.];
EXPORT CONTROL :
Cet email ne contient pas de données techniques
This email does not contain technical data
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170627/e8091aee/attachment.htm>
More information about the users
mailing list