Asked by JL
on 22 Aug 2019 at 20:50

I have a matrix, a

a = [1 2;

1 3;

1 5;

1 7;

1 8;];

and this matrix a, is emptied in each row per loop until the last one using this code from Matt J

a0=a;

for i=1:size(a,1)

a=a0;

a(i,:)=[],

end

which result in:

a = [1 3;

1 5;

1 7;

1 8;];

a = [1 2;

1 5;

1 7;

1 8;];

a = [1 2;

1 3;

1 7;

1 8;];

a = [1 2;

1 3;

1 5;

1 8;];

a = [1 2;

1 3;

1 5;

1 7;];

can I create another loop to calculate a certain value, w, from the results from each loop beginning with the orginal until the last one. After each loop answer value, w, is tabulated in matrix b

b = [w

w

w

w

w

w]

there 6 values of w since we consider the orginal a

Answer by Matt J
on 22 Aug 2019 at 21:44

Edited by Matt J
on 22 Aug 2019 at 22:01

Accepted Answer

Why not as follows,

b=nan(size(a,1),1); %pre-allocate

for i=1:size(a,1)

tmp=a;

tmp(i,:)=[],

b(i)=max(tmp(:))-min(tmp(:)); %example derived quantity

end

JL
on 22 Aug 2019 at 22:23

Hi Matt, yup it is not working for me. in fact, my matlab is going crazy.

for i=1:size(a,1)

a=a0;

a(i,:)=[],

% I PLACE CODE HERE TO CALCULATE Ws

end

This code above actually produces all the calculated values of w for each loop. But I need a code to put the values of w derived from each loop into a matrix, b.

b = [250; %from first loop

175; %from second loop

145; %from third loop

230; %from fourth loop

250; % from fifth loop

];

David Hill
on 22 Aug 2019 at 22:44

JL
on 27 Aug 2019 at 15:52

Thank you!

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Ted Shultz (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/477246-emptying-each-row-of-matrix-of-a-in-a-loop-then-uses-respective-matrices-produced-from-it-to-get-a-c#comment_738126

## JL (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/477246-emptying-each-row-of-matrix-of-a-in-a-loop-then-uses-respective-matrices-produced-from-it-to-get-a-c#comment_738128

## JL (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/477246-emptying-each-row-of-matrix-of-a-in-a-loop-then-uses-respective-matrices-produced-from-it-to-get-a-c#comment_738134

## David Hill (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/477246-emptying-each-row-of-matrix-of-a-in-a-loop-then-uses-respective-matrices-produced-from-it-to-get-a-c#comment_738137

Sign in to comment.