Matrix size is changed at each iteration.
1 次查看(过去 30 天)
显示 更早的评论
Hi, My matrix size is changing at each iteration and the dimensions don't match as a result. I thought to produce a zero matrix of higher dimensions and replace the zeros with the current row matrix but I can't seem to do it. The code is as follows. Is there any other way I can handle this problem?
Any help would be really appreciated.
Thank you.
Kingshuk
p2 = single(zeros(25));
preliminary_seed = [1 preliminary_seed];
if counter_1 == 1
p2(counter_1,:) = preliminary_seed;
else
seed1 = p2(counter_1-1,:);
seed2 = preliminary_seed;
if numel(seed2) > numel(seed1)
seed1(end+1:numel(seed2))= 0;
elseif numel(seed1) > numel(seed2)
seed2(end+1:numel(seed1)) = 0;
else
seed2;
end
p2(counter_1,:) = seed2;
end
6 个评论
per isakson
2016-12-8
编辑:per isakson
2016-12-8
Questions:
- Did you make this code yourself and thus know in some detail how it is intended to work?
- Do you use the debugging features "all the time"? If not, see Debug a MATLAB Program
Proposal:
- In the Editor group of the Toolstrip there is a button named Breakpoints. Activate "Stop on Errors"
- Start your program
- Inspect the values of variables in line which causes the error.
- Etc.
- Return here when you have specific questions.
per isakson
2016-12-8
This runs, but the result isn't useful
function p2 = cssm()
p2 = single(zeros(25));
preliminary_seed = [1,randi(12,1,24)];
for counter_1 = 1 : length( preliminary_seed )
if counter_1 == 1
p2(counter_1,:) = preliminary_seed;
else
seed1 = p2(counter_1-1,:);
seed2 = preliminary_seed;
if numel(seed2) > numel(seed1)
seed1(end+1:numel(seed2))= 0;
elseif numel(seed1) > numel(seed2)
seed2(end+1:numel(seed1)) = 0;
else
seed2;
end
p2(counter_1,:) = seed2;
end
end
end
I since I don't know neither the start value of preliminary_seed nor the intent ...
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!