필터 지우기
필터 지우기

For loop gives error: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

조회 수: 1 (최근 30일)
Having problems with making a For loop for example below. Desired outcome: skylineMat = 2x1 cell.
Example (without for loop: works):
skylineMat = true(90,360);
Q1 = inpolygon( repmat(azimV,length(altV),1) , repmat(altV',1,length(azimV)) , skyline_raw{1}(:,1) , skyline_raw{1}(:,2) );
skylineMat1 = skylineMat & ~ Q1;
Q2 = inpolygon( repmat(azimV,length(altV),1) , repmat(altV',1,length(azimV)) , skyline_raw{2}(:,1) , skyline_raw{2}(:,2) );
skylineMat2 = skylineMat & ~ Q2;
skylineMat = { {skylineMat1(:,:) } ; { skylineMat2(:,:) } }
Example (with for loop: gives me the error in the title):
skylineMat = true(90,360);
shapes_num = 2;
for s=1:shapes_num
Q(s) = inpolygon( repmat(azimV,length(altV),1) , repmat(altV',1,length(azimV)) , skyline_raw{s}(:,1) , skyline_raw{s}(:,2) );
skylineMat(s) = skylineMat & ~ Q(s);
end

답변 (1개)

KSSV
KSSV 2021년 3월 1일
This error occurs, when you try to save more number of elements than you initialized.
Example:
A = rand(10,5) ; % initialize array
A(1,:) = rand(1,5) ; % no error
A(2,:) = rand(1,7) ; % error, you have to save 1x5 but you tried to save 1x7, so error.
Use debug options and try to check the dimensions of RHS and then initialize LHS and then save.
If the dimensions are not known, try to save them into a cell.
Example:
A = cell(1,5) ;
A{1} = rand(1,5) ;
A{2} = rand(1,10) ;

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by