vectorise for loop in Octave

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

vectorise for loop in Octave

aurorax

Hello!


I am trying to vectorise the for loops of a script to make it faster and some of them look like the following:

R = dlmread('Rp.csv');

for m = 1:4
  eval(['node' num2str(m) '= R(m,:);']);
end

Here I am creating the variables node1, node2, node3, node4. But I am not able to do it as follows:
 
clear
R = dlmread('Rp.csv');
eval(['node' num2str(1:4) '= R(1:4,:);']);

Any suggestions on how to vectorise it or make them faster?

Thank you very much for your time
 



---------------

Aurora González Vidal                      Ph.D. in Data Analytics for Energy Efficiency                                  President of Murcia R Users Association (UMUR)
T. +34 868 88 7866                             Department of Information and Communication Engineering                gauss.inf.um.es/umur
[hidden email]                  Faculty of Computer Sciences
https://auroragonzalez.github.io/        University of Murcia                                                                                



Rp.csv (24K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: vectorise for loop in Octave

Octave - General mailing list
On 5/11/20 5:41 PM, AURORA GONZALEZ VIDAL wrote:

Hello!


I am trying to vectorise the for loops of a script to make it faster and some of them look like the following:

R = dlmread('Rp.csv');

for m = 1:4
  eval(['node' num2str(m) '= R(m,:);']);
end

Here I am creating the variables node1, node2, node3, node4. But I am not able to do it as follows:

'eval' and creating custom named variables seem to me the opposite to vectorization, which usually leverages Octave's "do this over the entire multidimentional array" operation.

What exactly are you trying to do? Why do you believe that node1 is better than node(1,:)?


clear
R = dlmread('Rp.csv');
eval(['node' num2str(1:4) '= R(1:4,:);']);

Any suggestions on how to vectorise it or make them faster?

Thank you very much for your time
 



---------------

Aurora González Vidal                      Ph.D. in Data Analytics for Energy Efficiency                                  President of Murcia R Users Association (UMUR)
T. +34 868 88 7866                             Department of Information and Communication Engineering                gauss.inf.um.es/umur
[hidden email]                  Faculty of Computer Sciences
https://auroragonzalez.github.io/        University of Murcia                                                          &nb sp;