0
votes

Lets say i have a matrix A of 300x65. the last column(65th) contains ordered values (1,2,3). the first 102 elements are '1', the second 50 elements are '2' and the remainder will be '3'.

I have another matrix B, which is 3x65 and i want to copy the first row of B by the number of '1's in matrix A. The second row of B should be copied by the number of '2's in in matrix A and the 3th row should be copied by the remaining value of matrix A. By doing this, matrix B should result in a 300x65 matrix.

I've tried to use the repmat function of matlab with no succes, does anyone know how to do this?

2
Can you paste you actual code.Nemesis

2 Answers

0
votes

There are many inconsistencies in your problem

first if you copy 1 row of B for every element of A(which will end up happening by your description) that will result in a matrix 19500x65

secondly copy its self is a vague term, do you mean duplicate? do you want to store the copied value into a new var?

what I gathered from your problem is you want to preform some operation between A and B to create a matrix and store it in B which in itself will cause the process to warp as it goes if you do not have another variable to store the result in

so i suggest using a third variable c to store the result in and then if you need it to be in b set b = C

also for whatever process you badly described I recommend learning to use a 'for' loop effectively because it seems like that is what you would need to use

syntax for 'for' loop

for i = [start:increment:end]
     //loops for the length of [start:increment:end]
     //sets i to the nth element of [start:increment:end] where n is the number of times the loop has run
end
0
votes

If I understand your question, this should do it

index = A(:,end);  % will be a column of numbers with values of 1, 2, or 3
newB = B(index,:); % B has 3 rows, which are copied as required by "index"

This should result in newB having the same number of rows as A and the same number of columns as the original B