i am doing a resampling problem in which i am trying to assign xp(j) to x(i) but the problem is both my xp and x are [2:1] ... how can i solve this problem .. please help ?? Thanks

for i = 1 : N u = rand; % uniform random number between 0 and 1 qs = 0; for j = 1 : N qs = qs+ q(j); if qs >= u x(i)= xp(j); break; end end end

*No products are associated with this question.*

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 3 Comments

## Patrik Ek (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/120983-help-solving-2-1-matrix-problem#comment_201148

what do you mean with [2:1] a vector from 2 to 1 increasing by 1 so that you get

[2:1] = 2? Some more input would be appreciated, I am not really sure what your problem is. Especially since your code is not stand alone. I have no idea what qtempsum (which does not even seem to be temp?!) or q(j), if you tries to overwrite x(i) xp(j) or if they a zero otherwise,... From the code I would assume x(i) and xp(j) are scalar, but you question makes me confused there. Also, in general I would begin to advise you to get rid of the for loops in some way, but since I am unsure of your problem, I cannot tell.## khalid (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/120983-help-solving-2-1-matrix-problem#comment_201412

thank you for replying ... sorry 'qtempsum' was qs (i made the correction) ... q(j) is an array ... by [2:1] i mean x and xp are m*n matrices with size 2*1 ... x and xp are non zero ... here in this part i am reassigning the xp to x .... Hope it helps you understand my problem ... Thanks again ... waiting for your reply

## Patrik Ek (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/120983-help-solving-2-1-matrix-problem#comment_201452

Still makes no sense. If there are m x n 2x1 matrices, how are they stored? In a cell? There are issues in the code since notation like

x(i)(read do not know anyhing about size and class for many of the variables) refers to a single matrix element in matlab, that I cannot even say where to start debugguing. If you want help you need to includexandxpin the example. The problem is related to size and indexing and I cannot help you if do not specify the variables you want to manipulate. It is like saying, "I have a dog, where do I live?". Please give something like,Log in to comment.