Non-constant expression or empty matrix

조회 수: 7 (최근 30일)
Yuri Rzhanov
Yuri Rzhanov 2019년 1월 11일
편집: Walter Roberson 2019년 1월 12일
Hi,
I have this error in Coder when am converting the following code, in the last line:
if ~isempty(coder.target)
coder.varsize('lattice', [100 100]);
lattice = zeros(0,0);
end
...
lattice = init_lattice(points,i);
if ~isempty(coder.target)
proposed_lattice = { 0 0 0 0 };
coder.varsize('proposed_lattice');
energy = zeros(4);
end
for j=1:4
proposed_lattice{j} = grow_lattice(lattice,points,j);
energy(j) = lattice_energy(proposed_lattice{j},points);
end
[~,min_idx] = min(energy);
if energy(min_idx) < previous_energy
lattice = proposed_lattice{min_idx};
...
'lattice' grows in size after each reassignment. First assignment by 'init_lattice' makes it 3*3, but as I understand, 'varsize' allows it to grow until 100*100. Would appreciate any clues.
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 1월 11일
편집: Walter Roberson 2019년 1월 12일
I would be more comfortable if you defined energy with two parameters to zeros .zeroes(4) is 4x4 but you are assigning to it like it was 1d column vector.
Yuri Rzhanov
Yuri Rzhanov 2019년 1월 12일
I can write
energy(j,1) = lattice_energy(proposed_lattice{j},points);
...
if energy(min_idx,1) < previous_energy
lattice = proposed_lattice{min_idx};
else
break;
end
but this doesn't change anything. Checking code readiness doesn't show anything wrong, but the coder (while generating trial code) throws this error, pointing to 'min_idx' which is a scalar. 'proposed_lattice' is a cell array, so {} are suitable, right?

댓글을 달려면 로그인하십시오.

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by