MATLAB: How can i allocate results in matrix with for loop allocationforfor loopmatgrix i tried store my results of exp()… in matrix with for loop. if you guys how would you do this? Best Answer This is MATLAB, so just get rid of the pointless loops entirely:>> w = 0:4;>> t = 0:9;>> y = exp(t.*w(:).*1i)y = Columns 1 through 5: 1.00000 + 0.00000i 1.00000 + 0.00000i 1.00000 + 0.00000i 1.00000 + 0.00000i 1.00000 + 0.00000i 1.00000 + 0.00000i 0.54030 + 0.84147i -0.41615 + 0.90930i -0.98999 + 0.14112i -0.65364 - 0.75680i 1.00000 + 0.00000i -0.41615 + 0.90930i -0.65364 - 0.75680i 0.96017 - 0.27942i -0.14550 + 0.98936i 1.00000 + 0.00000i -0.98999 + 0.14112i 0.96017 - 0.27942i -0.91113 + 0.41212i 0.84385 - 0.53657i 1.00000 + 0.00000i -0.65364 - 0.75680i -0.14550 + 0.98936i 0.84385 - 0.53657i -0.95766 - 0.28790i Columns 6 through 10: 1.00000 + 0.00000i 1.00000 + 0.00000i 1.00000 + 0.00000i 1.00000 + 0.00000i 1.00000 + 0.00000i 0.28366 - 0.95892i 0.96017 - 0.27942i 0.75390 + 0.65699i -0.14550 + 0.98936i -0.91113 + 0.41212i -0.83907 - 0.54402i 0.84385 - 0.53657i 0.13674 + 0.99061i -0.95766 - 0.28790i 0.66032 - 0.75099i -0.75969 + 0.65029i 0.66032 - 0.75099i -0.54773 + 0.83666i 0.42418 - 0.90558i -0.29214 + 0.95638i 0.40808 + 0.91295i 0.42418 - 0.90558i -0.96261 + 0.27091i 0.83422 + 0.55143i -0.12796 - 0.99178iIf you really want to use pointless nested loops, then try this:y = nan(5,10);for t = 0:4 for w = 0:9 y(t+1,w+1) = exp(t*w*1i) endend Related SolutionsMATLAB: Delete rows and columns with zeros in a multi level cell array matrix. fun = @(in)in(~cellfun(@(x)[strcmp(x,'0')||isempty(x)] , in));result = cellfun(fun, datafi2 , 'UniformOutput', false); MATLAB: Does the loop not work for the increment stated Your code is essentially correct. If you want all the itermediate results, you need to index āvā: for t= 0:1:20a= [t, sin(t), 0];b= [0, 0, cos(t)];v(t+1,:)= a + b;end Related QuestionCannot get the same result in GA as I get in linprogRead value from a text file and store into an arrayExtract certain lines in matriceHow to read a txt file having alphanumeric data and special characters. ? My text file is like this. I tried textread but could not get a result. any suggestion.
Best Answer