Dimension problem in for loop?

조회 수: 4 (최근 30일)
vimal kumar chawda
vimal kumar chawda 2021년 7월 2일
답변: Cris LaPierre 2021년 7월 3일
I have problem with dimensions. Please find the whole code in attachment.
clc;
clear all;
close all;
format long g;
load('Data\data.mat')
X_1 = reshape(transpose(coord{1:4,2:3}),[8,1]);
X_2 = reshape(transpose(coord{5:8,2:3}),[8,1]);
posteriori_standard_deviation = 1.02; %in meter
displacement_vector = [X_2-X_1];
F = [1 0 1 0 1 0 1 0]%; 0 1 0 1 0 1 0 1];
n=4;
x_gravity_epoch1 = (1/n)*(F* X_1);
x_gravity_epoch2 = (1/n)*(F* X_2);
X1_bar_i = X_1 - x_gravity_epoch1';
X2_bar_i = X_2 - x_gravity_epoch2';
% x_bar_i = x_bar_i';
% y_bar_i = y_bar_i';
for i=1:size(X1_bar_i)
H(i,:)= [0 X1_bar_i(i+1,1) X1_bar_i(i,1) -X1_bar_i(i+1,1) 0 1;X1_bar_i(i+1,1) X1_bar_i(i,1) 0 X1_bar_i(i,1) 1 0];
i=i+1;
end
The error is Unable to perform assignment because the indices on the left side are not compatible with the
size of the right side.

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 7월 3일
I believe the issue is that you are trying to assign a 2-row array into a single row of H. Hence, the dimension mismatch error. If your intent is to assign the array to 2 rows of H, then your row index must include both rows.
% Assignment to 2 rows works
A(1:2,:)=rand(2,6)
A = 2×6
0.8925 0.9049 0.9095 0.9129 0.5104 0.9256 0.1996 0.1794 0.4227 0.2812 0.9497 0.2225
% Assignment to 1 row doesn't work
A(3,:)=rand(2,6)
Unable to perform assignment because the size of the left side is 1-by-6 and the size of the right side is 2-by-6.

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by