Info
此问题已关闭。 请重新打开它进行编辑或回答。
Please help me to overcome the error of the following code
1 次查看(过去 30 天)
显示 更早的评论
A = diag([1 2 3 4 5 6 7 8 9]);
N_G=3;%No of group
B = cell(N_G,1);
sumB = cell(N_G,1);
for i=1:1:N_G
n=randi([2 6],1)% select No of UE randomly
idx=randsample(1:size(A,1),n)
B{i} = A(idx,:)
[rows, columns] = size(B{i});
% Get sum of columns and replicate vertically.
sumB{i} = repmat(sum(B{i}, 1), [rows, 1])
end
These are the errors which comes while running the code.Please help me to overcome it.
>> B{i} = A(idx,:)
The right hand side of this assignment has too few values to satisfy
the left hand side.
>> [rows, columns] = size(B{i})
Error using size
Too many output arguments.
>> sumB{i} = repmat(sum(B{i}, 1), [rows, 1])
Error using sum
Trailing string input must be 'double', 'native', 'default',
'omitnan' or 'includenan'.
0 个评论
回答(2 个)
Star Strider
2017-12-21
Your posted code runs for me without error.
This problem:
>> [rows, columns] = size(B{i})
Error using size
Too many output arguments.
is most likely caused by your having a variable named ‘size’ somewhere earlier in your code. You can confirm this with:
which size -all
If the first line of the output is:
size is a variable.
You have found the problem.
The second error most likely results from ‘rows’ not existing. However execution should have stopped with the first error and not thrown the second, and since your code runs for me without error, I have no idea what the problem could be with your sum call.
0 个评论
Image Analyst
2017-12-21
I don't know what it does, but your code runs fine for me -- no errors at all:
A = diag([1 2 3 4 5 6 7 8 9]);
N_G=3;%No of group
B = cell(N_G,1);
sumB = cell(N_G,1);
for i=1:1:N_G
n=randi([2 6],1)% select No of UE randomly
idx=randsample(1:size(A,1),n)
B{i} = A(idx,:)
[rows, columns] = size(B{i});
% Get sum of columns and replicate vertically.
sumB{i} = repmat(sum(B{i}, 1), [rows, 1])
end
B{i} = A(idx,:)
[rows, columns] = size(B{i})
sumB{i} = repmat(sum(B{i}, 1), [rows, 1])
2 个评论
Image Analyst
2017-12-21
This will help you solve the algorithmic error: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!