I am still trying to learn MATLAB. It would be helpful if I get some knowledge from this problem. So here is a simpler version of my problem. ( I wish to learn from this and use it in my actual problem)
I have Matrix defined by:
A=zeros(10,10);
for i=1:10
for j=1:10
A(j,i)=i*100+j;
end
end
I wish to pick 5 Random but Unique terms in the Matrix A, do some operation (for example: addition of all 5 terms) and from the result, I will make a column Matrix B by populating each row with one result from addition of 5 random unique terms in A, till I run out of all terms in A.
I know how to perform operations on the 5 terms from A and to populate B but I don't know how to get the 5 Random Unique terms from A. Can someone please help me with this.

 채택된 답변

James Tursa
James Tursa 2018년 2월 2일
편집: James Tursa 2018년 2월 2일

1 개 추천

A = your matrix
n = number of elements of A to pick at a time (must be exactly divisible in numel(A))
x = reshape(randperm(numel(A)),n,[]); % Create some random non-repeating indexing
for k=1:size(x,2)
% The elements of A to use for this iteration are A(x(:,k))
end

추가 답변 (0개)

제품

질문:

2018년 2월 2일

편집:

2018년 2월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by