Borrar filtros
Borrar filtros

Matrix size is changed at each iteration.

1 visualización (últimos 30 días)
Kingshuk Islam
Kingshuk Islam el 7 de Dic. de 2016
Comentada: per isakson el 8 de Dic. de 2016
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 comentarios
per isakson
per isakson el 8 de Dic. de 2016
Editada: per isakson el 8 de Dic. de 2016
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
per isakson el 8 de Dic. de 2016
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 ...

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by