Concatenating in a new matrix from inside a while loop

1 view (last 30 days)
Hiee.. I am trying store the new values of TP in a new matrix after some TP values are deleted inside the loop as the conditions are met. Then again, after the inside while loop ends, i want to set new conditions and perform operation on the old TP values and keep storing it in new matrix to perform some other condition on the new TP value and keep doing it. I am not able to find the right way of doing it. I would be very grateful for anyone's help expert in matlab. Thank you
s=1;
k=1;
num_pos= 1;
che= [0.01:0.05:10]';
size(che);
while s < length(che)
TP=X; %X is a n by 2 matrix
while k < length(D)
if D(num_pos,1) > abs(che(s)*xstd+xmean)
TP(num_pos,:)=[];
else
TP(num_pos,:) = X(num_pos,:);
num_pos = num_pos+1;
end
k = k+1;
% want to store the new TP values in a matrix(e.g "newmatrix") of n1 by 2
sensitivity(s) = (length(newmatrix)/250);
end
% bring my Old TP value which is equal to X ( n by 2 ) matrix
s=s+1;
end

Answers (1)

KSSV
KSSV on 4 Oct 2017
Edited: KSSV on 4 Oct 2017
YOu may initialize your newmatrix as nx2x2 matrix, stroe oldTP at 1 and new TP at 2. The below one will work with few changes accordingly.
s=1;
k=1;
num_pos= 1;
che= [0.01:0.05:10]';
size(che);
n=600;
count1 = 0 ;
sensitivity = cell([],[]) ;
while s < length(che)
count1 = count1+1 ;
count2 = 0 ;
TP=X; %X is a n by 2 matrix
newmatrix(:,:,1) = TP ;
while k < length(D)
count2 = count2+1 ;
if D(num_pos,1) > abs(che(s)*xstd+xmean)
TP(num_pos,:)=[];
else
TP(num_pos,:) = X(num_pos,:);
num_pos = num_pos+1;
end
k = k+1;
new_matrix= TP ;
% want to store the new TP values in a matrix(e.g "newmatrix") of n1 by 2
sensitivity{count1,count2} = (length(new_matrix)/250);
end
% bring my Old TP value which is equal to X ( n by 2 ) matrix
TP = newmatrix(:,:,1) ;
s=s+1;
end
sensitivity;
  2 Comments
HIRAKJYOTI BASUMATARY
HIRAKJYOTI BASUMATARY on 4 Oct 2017
Edited: HIRAKJYOTI BASUMATARY on 4 Oct 2017
Sir, i have edited the code and got the required results. Thank you very much sir. Now i am having trouble to store the sensitivity value from each loop, which is i think will be able to tackle.
s=1;
k=1;
num_pos= 1;
che= [0.01:0.05:10]';
size(che);
n=600;
while s < length(che)
TP=X; %X is a n by 2 matrix
newmatrix(:,:,1) = TP ;
while k < length(D)
if D(num_pos,1) > abs(che(s)*xstd+xmean)
TP(num_pos,:)=[];
else
TP(num_pos,:) = X(num_pos,:);
num_pos = num_pos+1;
end
k = k+1;
new_matrix= TP ;
% want to store the new TP values in a matrix(e.g "newmatrix") of n1 by 2
sensitivity(s) = (length(new_matrix)/250);
end
% bring my Old TP value which is equal to X ( n by 2 ) matrix
TP = newmatrix(:,:,1) ;
s=s+1;
end
sensitivity;
KSSV
KSSV on 4 Oct 2017
I have edited the answer..to save sensitivity.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!