How to cut and add values from every iteration. Please Help
Show older comments
p = [90 90 -45 0 0 45 45 0 -45]; p1 = p; %store temporary copy of p
p_descend = sort(p, 'descend');
p_ascend = sort(p,'ascend');
idx = [true diff(p)~=0];
q = p(idx); q1=q; %temporary copy of q
idx = fliplr([true, diff(fliplr(p))~=0]);
position_p = find(idx); pos = position_p;
ii = find(idx);
n = numel(ii);
layer1 = zeros(n,numel(p));
layer1(1,:) = p;
i1 = fliplr(ii);
for j = 2:n
layer1(j,:) = layer1(j-1,:);
layer1(j,[i1(j),end]) = layer1(j,[end,i1(j)]);
end
layer = reshape(layer1(2:end,:)',1,size(layer1,2),(size(layer1,1)-1));
I want to store last value of layer
means values should be
out(:,:,1) = [0];%add last value from every iteration
out(:,:,2) = [0 45];%last value of iteration 1 & 2
out(:,:,3) = [0 45 0];
out(:,:,4) = [0 45 0 -45];
out(:,:,5) = [0 45 0 -45 90];
and i need last values from every iterations
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!