MATLAB: How to collect non-integers from for loop in one matrix for loop eg: for k=1:.5:10 y(k)=[k] end this wont work i need output as y=1 1.5 2 2.5 and so on. Best Answer ii=0;for k=1:.5:10ii=ii+1 y(ii)=kendork=1:.5:10for ii=1:numel(k) y(ii)=k(ii)end Related SolutionsMATLAB: How to return the values of a loop You are computing k once for each value of i and overwriting it. If I understand what you want, try: i = 1:5; j = 0:5; k = zeros(numel(i),numel(j)); for a = 1:numel(i) for b = 1:numel(j) k(a,b) = i(a)^2 + i(a)*j(b) + j(b)^2; end end display(k) MATLAB: Nested Loop Script (Triangle) Here is the complete answer to all parts of the assignment:%%clearvars; clc%% Part 1.k=1;for ii = 1 : 5 for jj = 1 : ii if k >10 k=k-10; fprintf(num2str(k)); else fprintf(num2str(k)) ; end k = k+1; end fprintf('\n') ;end%% Part 2k = 65 ;for ii = 1 : 5 for jj = 1 : ii fprintf(char(k)) ; k = k + 1 ; end fprintf('\n') ;end%% Part 3. Numbersk=5;for ii = 1 : 5 for jj = 1 : ii if k >10 k=k-10; fprintf(num2str(k)); else fprintf(num2str(k)) ; end k = k+1; end fprintf('\n') ;end%% Part 3. Lettersk = 68 ;for ii = 1 : 5 for jj = 1 : ii fprintf(char(k) ) ; k = k + 1 ; end fprintf('\n') ;end Related QuestionWorkaround for subscript indices being non-integers and non-logicalsHow to restore output of for loop in matrixIn for loop, add same fractional value to all non-integers in the vectorHow to store values as array
Best Answer