The size of the indicated variable or array appears to be changing with each loop iteration. Commonly, this message appears because an array is growing by assignment or concat

조회 수: 1(최근 30일)
Hosein Jeddi 2021년 7월 19일
댓글: Stephen 2021년 7월 19일
clc
clear
h = 1;
r = 0:h:20;
z = 0:h:20;
[rgrid,zgrid] = meshgrid(r,z);
zgrid = flip(zgrid);
b1=[];
for i=1:size(rgrid,1)*size(zgrid,2)
if zgrid(i) == min(min(zgrid))
b1 = [b1 i];
end
end
댓글 수: 1표시숨기기 없음
Stephen 2021년 7월 19일

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

채택된 답변

Stephen 2021년 7월 19일
편집: Stephen 2021년 7월 19일
h = 1;
r = 0:h:20;
z = 0:h:20;
[rgrid,zgrid] = meshgrid(r,z);
zgrid = flip(zgrid)
zgrid = 21×21
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
Simpler, faster code:
b2 = find(zgrid==min(zgrid(:))).'
b2 = 1×21
21 42 63 84 105 126 147 168 189 210 231 252 273 294 315 336 357 378 399 420 441
or even simply:
n3 = numel(z);
b3 = n3:n3:n3*numel(r)
b3 = 1×21
21 42 63 84 105 126 147 168 189 210 231 252 273 294 315 336 357 378 399 420 441
b1 = [];
for i = 1:size(rgrid,1)*size(zgrid,2)
if zgrid(i) == min(min(zgrid))
b1 = [b1 i];
end
end
b1
b1 = 1×21
21 42 63 84 105 126 147 168 189 210 231 252 273 294 315 336 357 378 399 420 441

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

Community Treasure Hunt

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

Start Hunting!

Translated by