Thanks for your reply, really.
I also think it is a multithreading issue. But what doesn't make sense is that I could push the 4 cores to 100% before changing stuff in the code. Does this mean that:
1. ASSIGNIN not being multithreaded? It is the only weird function I added since I changed the code. It is important to remember that before the changes the code ran faster (I think it is because the 4 cores were running to the top (100%), which is not the case now). I mean, there is not a new bottleneck or critical line I added, the profiler shows that the critical lines are lines that I did not touch and where there waaay before all of this. It is just A LOT slower and now processors won't reach 100% load. So obviously it is NOT a more efficient code just using what it needs out of the processors.
2. If the problem is with ASSIGNIN, shouldn't the profiler detect that it is this functions which is slowing down everything else? Why does the profiler say that the fucntion that calls ASSIGNIN is super fast? Of course, if you run the whole code with just 1 core, then the profiler shows logical stuff, but to my opinion it should also show bottlenecks related to something in the code not letting your program keep the processors to their limit, or something like that.
I already read the docs on multithreading but they lack a lot of info about these cases, in my opinion. For example, if I have a script that can run everything multithreaded and then I add a function that is not multithreaded at the middle, will it run everything with just one core? Or will it switch from multithreading to just one core and back again to multi?
I am really confused, and what I really think is happening is that ASSIGNIN is not multithreaded, but MATLAB runs everything else multithreading, switches off to 1 core to run this functions, and then switches back to multi cores to run the rest (is this even possible?). If this is the case it means that this multi-mono core alternating REALLY slows down the processing, and this is not shown by the profiler or anything else. In this case the profiler should say something like "this line is the only line that you cannot process with N cores, this will slow your code like you wouldn't believe", or something like that haha
I don't have too much time to try and write the code without ASSIGNIN to see if that is the problem, but when I do I will post what I found. In the mean time more opinions are very welcomed.