I have decided to do some repetition in Matlab during this summer so I'm doing a lot of assignments again that I have already finished a couple of months ago. Though, I stumble upon a certain assignment and my solution would be:
load talv_stor=[];v_liten=[];v_mellan=[];for i=1:length(V) if V(i)>=10 v_stor = v_stor + V(i); elseif V(i)<=-10 v_liten = v_liten + V(i); else v_mellan = v_mellan + V(i); endendv_storv_mellanv_liten
I think it's pretty straightfoward what I want my code to do. This gave me empty vectors and I was confused why, so I checked my earlier solution:
load talt = 0;v_stor = [];v_mellan = [];v_liten = [];for i= 1:length(V) if V(t+1)>= 10 v_stor=[v_stor V(t+1)]; elseif V(t+1)<=-10 v_liten = [v_liten V(t+1)]; else v_mellan=[v_mellan V(t+1)]; end t=t+1;endv_storv_mellanv_liten
So my question is, why is my second solution wrong and how come, in my earlier solution, that I used V(t+1)? It looks the same to me.
Edit: Vector V is of size 1000×1
Best Answer