How to cut and add values from every iteration. Please Help

2 ビュー (過去 30 日間)
Triveni
Triveni 2016 年 1 月 26 日
編集済み: Triveni 2016 年 2 月 1 日
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

採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 1 月 26 日
編集済み: Andrei Bobrov 2016 年 1 月 26 日
Hi Ranjan! Edited loop for..end in your code.
output1 = cell(n-1,1);
for jj = 2:n
layer1(jj,:) = layer1(jj-1,:);
layer1(jj,[i1(jj),end]) = layer1(jj,[end,i1(jj)]);
output1{jj-1} = layer1(jj,(end-jj+2):end);
end
  1 件のコメント
Triveni
Triveni 2016 年 1 月 27 日
編集済み: Triveni 2016 年 1 月 27 日
out1(:,:,1) = [0];%add last value from every iteration
out1(:,:,2) = [0 45];%last value of iteration 1 & 2
out1(:,:,3) = [0 45 0];%last value of iteration 1,2&3
out1(:,:,4) = [0 45 0 -45];%last value of iteration 1,2,3&4
out1(:,:,5) = [0 45 0 -45 90];%last value of iteration 1,2,3,4&5
?? and please correct this too
cell2mat(reshape(output1,1,1,size(output1,1)),1,[],[])
Thanks sir....You have done lots for me....you have given full support in my thesis.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel Computing についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by