MATLAB: How to save matrix created in each iteration n=1;while n<4 k=[1 2 3 4;5 6 7 8]; k=k*n; n=n+1; display(n) display(k)end Best Answer One of waysn=1;k=[1 2 3 4;5 6 7 8];out = zeros([size(k),3]);while n<4 k=k*n; out(:,:,n) = k; n=n+1;end Related SolutionsMATLAB: I keep getting an error saying index exceeds matrix dimensions Initialize n at 0:n=0;t(1)=0;T(1)=50;Tout=375; k=0.0035; time=[0.0,0.5,2.0];temps=[106,96,102];h=30;while T<160 n=n+1;slope=-k*(T(n)-Tout);t(n+1)=t(n)+h;T(n+1)=T(n)+h*slope; endor increase n later in the loop:n=1;t(1)=0;T(1)=50;Tout=375; k=0.0035; time=[0.0,0.5,2.0];temps=[106,96,102];h=30;while T<160 slope=-k*(T(n)-Tout);t(n+1)=t(n)+h;T(n+1)=T(n)+h*slope;n=n+1;end MATLAB: If-then with a range You're almost there!clearclcM = 1:10;N = zeros(1,length(M));for k = 1:length(M) if mod(M(k),2) == 1 N(k) = M(k)+1; else N(k) = M(k)+2; endendNN = 2 4 4 6 6 8 8 10 10 12 Related QuestionInsertion of the indexWhat is the error in this codeSplitting a vector at sign change
Best Answer