help solving [2:1] matrix problem

1 view (last 30 days)
khalid
khalid on 11 Mar 2014
Edited: Patrik Ek on 12 Mar 2014
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
  3 Comments
khalid
khalid on 12 Mar 2014
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
Patrik Ek on 12 Mar 2014
Edited: Patrik Ek on 12 Mar 2014
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 include x and xp in 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,
xp = ?; % xp is n x m matrices somehow implies a cell here, but you
x = ?; % do not use syntax for cell access which is confusing, which is
q = ?; % why these must be stated. Simplified code require correct syntax.
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

Sign in to comment.

Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!