MATLAB: For Loop in Data datafor loop How can I convert those y's in just one FOR loop? x= [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 ]; y1=x(2:end) – x(1:end-1) y2=x(3:end) – x(1:end-2) y3=x(4:end) – x(1:end-3) y4=x(5:end) – x(1:end-4) Best Answer x = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 ];y = cell(1, 4);for k = 1:4 y{k} = x(1-k:end) - x(1:end-k);endPrefer a cell array instead of hiding indices in the names of variables. Related SolutionsMATLAB: The program is not running, and how to run it You cannot use an indexed variable for a "for" loop variable.By the way:X = dec2bin(0:2^9-1) - '0';mask = sum(X, 2) == 5;X5 = X(mask, :);Now X5 is a (something) by 9 array in which every row has sum 5. You can work on your processing from there. MATLAB: I am getting the following error for the below code: Subscript indices must either be real positive integers or logicals. How can i remove that error. You havet=0:.1:10;so t is a vector containing 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0You havewhile (y(t)>=0)but t is the vector discussed above, so your line is equivalent to askingwhile y([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]) >= 0However, this attempts to subscript y with 0 and non-integers.I suggest you have a look at https://www.mathworks.com/matlabcentral/answers/353353-how-can-i-use-interval-with-decimal-at-the-end-of-a-count-in-for-loop-e-g-t-1-1-18-7#comment_478299 Related QuestionHow to find the values of 2 variables that will make the matrix rank 6What’s the best way to add semi-colons after each element of a matrixHot to fit two curves under interdependent constraintHow to generate random amplitude pulse signal
Best Answer