help solving [2:1] matrix problem
1 view (last 30 days)
Show older comments
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
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
Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!